Skip to content

feat(webhook): add POST /scan endpoint for manual scan triggers#4

Merged
ttlequals0 merged 1 commit intomainfrom
feature/manual-scan-endpoint
Apr 12, 2026
Merged

feat(webhook): add POST /scan endpoint for manual scan triggers#4
ttlequals0 merged 1 commit intomainfrom
feature/manual-scan-endpoint

Conversation

@ttlequals0
Copy link
Copy Markdown
Owner

Summary

  • Adds `POST /scan` to the webhook HTTP server so a scan cycle can be triggered on demand without modifying environment variables or redeploying.
  • `POST /scan` runs a full scan across all non-excluded libraries (same code path as the periodic timer).
  • `POST /scan?library=<id|name>` scans a single library. Accepts the Plex section ID or a case-insensitive library name.
  • Returns `202 Accepted` immediately and runs the scan in a goroutine. `409` if a scan is already in progress, `404` if the `library` param is unknown, `405` for non-POST. `503` if the scanner is not wired up (defensive).
  • Motivation: after the webhook 400 regression fixed in v1.2.3, there's no built-in way to backfill items that Plex failed to deliver during the outage without flipping `WEBHOOK_ONLY`. `/scan` gives operators a clean escape hatch.

Design notes

  • New `webhook.Scanner` interface with `RunAll()` and `RunLibrary(id, name, mediaType)`.
  • Implemented by `scanRunner` in `cmd/labelarr/main.go`, which replaces the previous inline `processFunc` closure. The periodic timer now also calls `scanner.RunAll()`, so there is a single code path.
  • Concurrency: a `sync.Mutex`-protected `scanning` flag on `webhook.Server` returns `409` if a scan is already running, preventing stacked full scans. Per-library mutexes in the processor continue to protect webhook-driven `ProcessSingleItem` against the running scan.
  • No auth on `/scan` — matches the existing `/webhook` and `/health` endpoints. The service is intended to be LAN-only.

Test plan

Adds a manual scan trigger so operators can force a catchup cycle
without toggling WEBHOOK_ONLY. POST /scan runs a full scan; POST
/scan?library=<id|name> targets a single library. Returns 202 on
accept, 409 on concurrent scan, 404 on unknown library. A Scanner
interface is introduced and implemented by a scanRunner in main;
the periodic timer now uses the same code path.
@ttlequals0 ttlequals0 merged commit 16d3b48 into main Apr 12, 2026
@ttlequals0 ttlequals0 deleted the feature/manual-scan-endpoint branch April 20, 2026 13:25
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.

1 participant