feat: add POST /api/expedition/check endpoint#350
Conversation
Add a dedicated HTTP endpoint to check and collect completed expeditions. This allows the GUI frontend to trigger expedition collection immediately after connecting to the emulator, preventing expedition pages from blocking subsequent tasks. Also bump version to 2.0.4.dev1 for testing.
There was a problem hiding this comment.
Pull request overview
Adds a new FastAPI endpoint to let the GUI trigger expedition collection on demand, decoupling expedition checks from the backend scheduler’s fight intervals.
Changes:
- Add
POST /api/expedition/checkthat callscollect_expedition(ctx)viaasyncio.to_thread, returning 409 when a task is running and 503 when the system isn’t started. - Update module docstring to list the new endpoint.
- Bump package version to
2.0.4.dev1.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
autowsgr/server/main.py |
Adds the new expedition check/collect HTTP endpoint and documents it in the module header. |
autowsgr/__init__.py |
Updates the package version for the test release. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if task_manager.is_running: | ||
| raise HTTPException(status_code=409, detail='任务执行中,无法检查远征') | ||
|
|
||
| from autowsgr.ops.expedition import collect_expedition | ||
|
|
||
| try: | ||
| result = await asyncio.to_thread(collect_expedition, ctx) |
There was a problem hiding this comment.
/api/expedition/check currently has no mutual-exclusion against concurrent calls (e.g., two clients or a retry). Since collect_expedition() drives UI navigation and device control, concurrent executions can interfere with each other and leave the game in an inconsistent state. Add a server-side guard (e.g., a module-level asyncio.Lock/flag) to serialize this endpoint, and consider sharing the same lock with task start so a task can’t begin while an expedition check is in progress (and vice versa).
Summary
Add a dedicated HTTP endpoint
POST /api/expedition/checkto check and collect completed expeditions.Motivation
The GUI frontend needs to trigger expedition collection immediately after connecting to the emulator, preventing expedition pages from blocking subsequent tasks. Previously, expedition checking was only done internally by the backend TaskScheduler during fight intervals, with no way for the frontend to trigger it on demand.
Changes
autowsgr/server/main.py: AddPOST /api/expedition/checkendpoint that callscollect_expedition(ctx)viaasyncio.to_thread. Returns 409 if a task is running, 503 if system not started.autowsgr/__init__.py: Bump version to2.0.4.dev1(test release).Frontend Integration
The GUI frontend (AutoWSGR-GUI) calls this endpoint:
Both calls are non-blocking with graceful error handling.