Skip to content

feat(rest-api): [#2309] migrate token lifecycle - #2316

Merged
josecelano merged 2 commits into
torrust:developfrom
josecelano:2309-1488-si-12-migrate-rest-api-token-lifecycle
Sep 23, 2026
Merged

josecelano merged 2 commits into
torrust:developfrom
josecelano:2309-1488-si-12-migrate-rest-api-token-lifecycle

Conversation

@josecelano

Copy link
Copy Markdown
Member

Summary

  • Add an additive token-aware REST API lifecycle that retains the server and drain-controller tasks.
  • Supervise REST child tasks through JobManager cancellation, including startup rollback and runtime-error outcomes.
  • Preserve legacy REST start/stop behavior and add deterministic lifecycle, bootstrap, and direct SIGTERM/rebind evidence.

Validation

  • cargo test -p torrust-tracker-axum-rest-api-server server::tests
  • cargo test -p torrust-tracker bootstrap::jobs::tracker_apis
  • cargo test -p torrust-tracker it_should_cancel_the_rest_api_component_through_the_job_manager
  • linter all
  • Installed pre-commit and pre-push hooks, including nightly workspace checks, documentation build, and full tests
  • Direct tracker-binary SIGTERM and REST listener rebind verification

Closes #2309

Copilot AI lite review requested due to automatic review settings September 23, 2026 11:03
@josecelano josecelano self-assigned this Sep 23, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

Review effort: Lite
Findings: 5 Medium severity

Open (5)
What changed in this PR

This PR migrates the REST API lifecycle to a token-aware, JobManager-supervised model that explicitly retains and joins both the REST server task and its drain-controller, while preserving the legacy start/stop behavior.

Changes:

  • Add a token-aware ApiServer::start_with_cancellation path that returns both runtime and drain-controller handles, plus registration rollback.
  • Update bootstrap supervision to await server + drain-controller on cancellation, independent completion, and runtime failure.
  • Add deterministic tests and issue-local verification evidence (including direct SIGTERM + listener rebind).
File Description
src/​bootstrap/​jobs/​tracker_apis.rs Switches REST API job to token-aware start + adds supervisor that joins runtime and drain-controller; adds unit tests for completion/failure semantics.
src/​app.rs Propagates JobManager cancellation via child token; adds integration test asserting http_api is cancelled via JobManager.
packages/​axum-rest-api-server/​src/​server.rs Introduces start_with_cancellation, CancellationRunning, and typed runtime error; adds tests for drain and listener release on registration failure.
packages/​axum-rest-api-server/​Cargo.toml Adds tokio-util dependency to support CancellationToken.
docs/​issues/​open/​2309-1488-si-12-migrate-rest-api-token-lifecycle/​*.md Records deterministic + manual verification evidence and retrospective notes for #2309.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/app.rs Resolved
Comment thread src/bootstrap/jobs/tracker_apis.rs Resolved
Comment thread src/bootstrap/jobs/tracker_apis.rs Resolved
Comment thread src/bootstrap/jobs/tracker_apis.rs Resolved
@josecelano
josecelano force-pushed the 2309-1488-si-12-migrate-rest-api-token-lifecycle branch from 1d9575c to 4a73235 Compare September 23, 2026 11:51
@josecelano

Copy link
Copy Markdown
Member Author

ACK 4a73235

@josecelano
josecelano merged commit 996ac6f into torrust:develop Sep 23, 2026
21 checks passed

This branch was previously deployed

1 inactive deployment
coverage — 4a732354 Deployed Sep 23, 2026 by josecelano via Generate Coverage Report #2269
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.

Migrate REST API to token lifecycle

2 participants