Skip to content

feat: add POST /api/expedition/check endpoint#350

Merged
yltx merged 1 commit intoOpenWSGR:mainfrom
yltx:feat/expedition-api
Mar 6, 2026
Merged

feat: add POST /api/expedition/check endpoint#350
yltx merged 1 commit intoOpenWSGR:mainfrom
yltx:feat/expedition-api

Conversation

@yltx
Copy link
Copy Markdown
Contributor

@yltx yltx commented Mar 6, 2026

Summary

Add a dedicated HTTP endpoint POST /api/expedition/check to 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: Add POST /api/expedition/check endpoint that calls collect_expedition(ctx) via asyncio.to_thread. Returns 409 if a task is running, 503 if system not started.
  • autowsgr/__init__.py: Bump version to 2.0.4.dev1 (test release).
  • Module docstring updated to list the new endpoint.

Frontend Integration

The GUI frontend (AutoWSGR-GUI) calls this endpoint:

  1. Immediately after system start (before entering idle state)
  2. Every 15 minutes via the expedition timer

Both calls are non-blocking with graceful error handling.

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.
Copilot AI review requested due to automatic review settings March 6, 2026 08:14
@yltx yltx merged commit a30d7a5 into OpenWSGR:main Mar 6, 2026
2 of 3 checks passed
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/check that calls collect_expedition(ctx) via asyncio.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.

Comment thread autowsgr/server/main.py
Comment on lines +457 to +463
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)
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/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).

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants