Bookability: run date refresh synchronously, update timestamp immediately
Backend now awaits the refresh in a thread executor instead of queuing a background task, so the response returns only after data is written. Frontend drops the 3s setTimeout and invalidates the cache immediately on success. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
7223ae9c30
commit
1612468122
2 changed files with 7 additions and 9 deletions
|
|
@ -607,17 +607,18 @@ def _refresh_date_sync(rate_date: date):
|
||||||
@router.post("/refresh-date/{rate_date}")
|
@router.post("/refresh-date/{rate_date}")
|
||||||
async def refresh_single_date(
|
async def refresh_single_date(
|
||||||
rate_date: str,
|
rate_date: str,
|
||||||
background_tasks: BackgroundTasks,
|
|
||||||
current_user: dict = Depends(get_current_user)
|
current_user: dict = Depends(get_current_user)
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Trigger a refresh of rates for a single date from Newbook.
|
Trigger a refresh of rates for a single date from Newbook.
|
||||||
Runs in background - returns immediately.
|
Runs synchronously so the client can invalidate its cache immediately on response.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
target_date = date.fromisoformat(rate_date)
|
target_date = date.fromisoformat(rate_date)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise HTTPException(status_code=400, detail="Invalid date format. Use YYYY-MM-DD")
|
raise HTTPException(status_code=400, detail="Invalid date format. Use YYYY-MM-DD")
|
||||||
|
|
||||||
background_tasks.add_task(_refresh_date_sync, target_date)
|
import asyncio
|
||||||
return {"status": "queued", "date": rate_date, "message": f"Refreshing rates for {rate_date}"}
|
loop = asyncio.get_event_loop()
|
||||||
|
await loop.run_in_executor(None, _refresh_date_sync, target_date)
|
||||||
|
return {"status": "success", "date": rate_date, "message": f"Rates refreshed for {rate_date}"}
|
||||||
|
|
|
||||||
|
|
@ -250,11 +250,8 @@ const Bookability: React.FC = () => {
|
||||||
return res.data
|
return res.data
|
||||||
},
|
},
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
// Refetch after a short delay to allow background task to complete
|
queryClient.invalidateQueries({ queryKey: ['rate-matrix'] })
|
||||||
setTimeout(() => {
|
setRefreshingDate(null)
|
||||||
queryClient.invalidateQueries({ queryKey: ['rate-matrix'] })
|
|
||||||
setRefreshingDate(null)
|
|
||||||
}, 3000)
|
|
||||||
},
|
},
|
||||||
onError: () => setRefreshingDate(null),
|
onError: () => setRefreshingDate(null),
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue