Enqueue Drive sync as a Django task and return 202 (#57).
Sync now / webhooks / cron share enqueue_drive_sync so HTTP no longer blocks on Drive list/ingest. ImmediateBackend still runs in-process via a background thread; status and errors stay on the connection for FE poll.
This commit is contained in:
@@ -235,7 +235,7 @@ true for Founders/Pro/Business/Backer, false for Standard by default).
|
||||
| `GET /api/drive/connections/` | Caller's personal connections + their company's company connections |
|
||||
| `DELETE /api/drive/connections/<id>/` | Disconnect (owner for personal, company manager for company) — deactivates + clears tokens, keeps history |
|
||||
| `POST /api/drive/connections/<id>/resources/` | `{ "resource_ids": [...], "resource_labels": [...] }` — folder/shared-drive/site ids to sync; empty = provider root |
|
||||
| `POST /api/drive/connections/<id>/sync/` | Sync now (`chat_backend/services/drive_sync.py::sync_connection`) |
|
||||
| `POST /api/drive/connections/<id>/sync/` | Enqueue sync now (`chat_backend/drive_tasks.py`) — returns **202** with `connection.last_sync_status=pending`; poll `GET /api/drive/connections/` for `ok` / `error` + `last_sync_error` |
|
||||
|
||||
**Provider scope differences:**
|
||||
- Google: same `drive.readonly` scope for personal and company; company sync
|
||||
@@ -243,10 +243,12 @@ true for Founders/Pro/Business/Backer, false for Standard by default).
|
||||
- Microsoft: personal uses `Files.Read`; company uses `Files.Read.All
|
||||
Sites.Read.All` and syncs SharePoint sites (`selected_resource_ids` = site ids).
|
||||
|
||||
**Workers / webhooks (#52):**
|
||||
- `python manage.py sync_drive_connections [--connection-id N]` — cron/worker entry point.
|
||||
**Workers / webhooks (#52, #57):**
|
||||
- `python manage.py sync_drive_connections [--connection-id N]` — enqueue sync tasks (default).
|
||||
- `python manage.py sync_drive_connections --sync-now` — run sync inline in this process (cron/debug).
|
||||
- Django 6 `TASKS` (see `settings.py`): default `ImmediateBackend` runs tasks in-process; Sync now still returns 202 by dispatching on a background thread. Swap `TASKS` to a durable queue + worker for production scale.
|
||||
- `POST /api/drive/webhooks/google/` / `POST /api/drive/webhooks/microsoft/` —
|
||||
provider push-notification stubs (`AllowAny`); acknowledge `200` and call
|
||||
provider push-notification stubs (`AllowAny`); acknowledge `200` and enqueue
|
||||
`sync_connection` when the notification's `connection_id` is resolvable,
|
||||
else just `200` (no-op). Microsoft's subscription-creation `validationToken`
|
||||
handshake is echoed back as `text/plain`.
|
||||
|
||||
Reference in New Issue
Block a user