Skip to content

[ext-api] Phase stop endpoint: gracefully halt a running phase #1290

@zbnerd

Description

@zbnerd

What to build

A new HTTP endpoint POST /api/internal/stop/phase/{phaseName} that requests graceful shutdown of a running phase. The phase finishes its current chunk / record batch, then stops; no half-written chunks, no abrupt executor interrupts.

The pattern to follow already exists in ItemEquipmentContinuousLoop: an AtomicBoolean shutdown flag, a ReentrantLock + condition for the lock-protected state machine, and an AtomicBoolean started/running/shutdown triplet. Apply the same shape to each phase-specific executor (or to a shared component if the existing scheduler executor is reused).

RunStatusTracker gets a new terminal phase STOPPED. When a phase run ends because of a stop request (not natural completion / failure), the tracker transitions to STOPPED instead of COMPLETED. The existing isTerminal predicate already covers this since STOPPED is a third terminal value.

The stop endpoint accepts X-Airflow-Run-Id for correlation but is best-effort: a stop requested for a phase that isn't running returns 200 with "status": "NOT_RUNNING" and the currently-active runId (if any) so Airflow can correlate.

Acceptance criteria

  • POST /api/internal/stop/phase/ITEM_EQUIPMENT halts a running ITEM_EQUIPMENT loop within one chunk boundary (≤ 30s)
  • Same endpoint works for each phase
  • Stopped phase run shows phase=STOPPED in /run-status and counts as terminal
  • Stopping a phase that isn't running returns 200 with "status": "NOT_RUNNING" (not 404 / 409)
  • No half-written chunks in MinIO after stop (verify by listing the run prefix)
  • A new phase can be triggered immediately after a stop on the same phase
  • Existing daily run is unaffected by a stop request for a different phase (no cross-phase interference)

Blocked by

Metadata

Metadata

Assignees

No one assigned

    Labels

    ready-for-agentFully specified, ready for an AFK agent

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions