Skip to content

Add /-/tasks introspection endpoint for supervised background tasks - #2892

Open
asg017 wants to merge 4 commits into
asg017/first-request-5-wrapper-reorderfrom
asg017/first-request-6-tasks-endpoint
Open

Add /-/tasks introspection endpoint for supervised background tasks#2892
asg017 wants to merge 4 commits into
asg017/first-request-5-wrapper-reorderfrom
asg017/first-request-6-tasks-endpoint

Conversation

@asg017

@asg017 asg017 commented Aug 31, 2026

Copy link
Copy Markdown
Collaborator

Adds new /-/tasks and /-/tasks.json endpoints for monitoring new "background tasks" introduced in #2889 , similar to /-/threads. It requires the permissions-debug permission like /-/threads and friends.

$ curl http://localhost:8010/-/tasks.json
{
  "ok": true,
  "tasks": [
    {
      "name": "datasette-cron",
      "state": "running",
      "plugin": "cron",
      "started_at": "2026-09-02T16:40:07.082274+00:00",
      "exception": null
    }
  ],
  "launched": true
}

🤖 Claude-generated PR description

Sixth and final PR in the startup/lifecycle stack, on top of #2891.

What this does

Adds a /-/tasks (and /-/tasks.json) introspection endpoint listing every supervised background task registered via datasette.add_background_task() (#2889), plus whether the launch phase has run.

Changes

  • datasette/app.py: new _tasks() data method exposed through JsonDataView at /-/tasks, guarded by the existing permissions-debug permission (same as /-/threads). Each task reports name, state, plugin, started_at, and a repr() of its exception if it crashed.
  • datasette/background_tasks.py: public launched property on the supervisor so the endpoint can distinguish "no tasks registered" from "registered but launch hasn't fired yet".
  • docs/introspection.rst and docs/json_api.rst: documents the endpoint.

Docs

Rolled down from the former docs-only tip PR (#2893), this PR now also carries the stack's capstone docs:

  • docs/introspection.rst: /-/tasks docs cross-reference the background-task API and lifecycle sections.
  • docs/internals.rst: the API reference sections mention /-/tasks where relevant.
  • docs/changelog.rst: the full 1.0a39 release notes for the whole stack — single-event-loop serve, lifespan startup, the background-tasks API, the shutdown() hook, the asgi_wrapper reorder, /-/tasks — including the "Migrating away from asgi_wrapper bootstrap hacks" guide.

Tests

New tests/test_tasks_endpoint.py covering the payload shape, permission gating, and states; /-/tasks added to the endpoint inventories in tests/test_permissions.py and tests/test_success_envelope.py.

Stack created with GitHub Stacks CLIGive Feedback 💬

@asg017
asg017 force-pushed the asg017/first-request-6-tasks-endpoint branch from b776d76 to 86ba1d4 Compare August 31, 2026 20:05
@asg017
asg017 force-pushed the asg017/first-request-6-tasks-endpoint branch from 86ba1d4 to c8ab289 Compare August 31, 2026 20:27
@codecov

codecov Bot commented Aug 31, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 0.00%. Comparing base (c2f7735) to head (66b5291).

Files with missing lines Patch % Lines
datasette/app.py 0.00% 3 Missing ⚠️
datasette/background_tasks.py 0.00% 3 Missing ⚠️
Additional details and impacted files
@@                          Coverage Diff                           @@
##           asg017/first-request-5-wrapper-reorder   #2892   +/-   ##
======================================================================
  Coverage                                    0.00%   0.00%           
======================================================================
  Files                                          74      74           
  Lines                                       12461   12467    +6     
======================================================================
- Misses                                      12461   12467    +6     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@asg017
asg017 force-pushed the asg017/first-request-6-tasks-endpoint branch from c8ab289 to 3683361 Compare August 31, 2026 21:25
@simonw
simonw force-pushed the asg017/first-request-6-tasks-endpoint branch from 3683361 to e0644de Compare September 1, 2026 16:32
@simonw
simonw force-pushed the asg017/first-request-6-tasks-endpoint branch from e0644de to 4a637ea Compare September 1, 2026 16:39
@asg017
asg017 marked this pull request as ready for review September 2, 2026 16:42
asg017 and others added 4 commits September 2, 2026 09:49
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012U7coQfVu8nK2R4q2mCULA
Rolled down from the stack's docs-only tip PR: introspection docs now
link to the background-task API sections, the internals docs mention
/-/tasks where relevant, and the full 1.0a39 changelog (including the
asgi_wrapper migration guide) lands here at the top of the stack.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012U7coQfVu8nK2R4q2mCULA
@asg017
asg017 force-pushed the asg017/first-request-6-tasks-endpoint branch from 99e12b9 to 66b5291 Compare September 2, 2026 16:49
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