Expand description
Context that follows work off the request thread — see
task_context::TaskContext. tokio::spawn inherits no
task_local!, so deferred work starts with none of its caller’s
ambient context unless it is carried deliberately.
Context that follows work off the request thread.
tokio::spawn does not inherit tokio::task_local!, so a job runs
with none of the ambient context its caller had. An audit row written
from a job records system — so “who deleted this customer?” is a
dead end whenever a job did it.
§An explicit list, not every task-local
It copies the task-locals named below, and only those. Declaring a
new task_local! does not opt it in.
| task-local | copied? | why |
|---|---|---|
audit::AUDIT_SOURCE (+ its tenant binding) | yes | who triggered the work |
i18n::timezone::ACTIVE_TZ | yes | a formatting preference |
sql::executor::atomic::BLOCK | no | the caller’s live transaction and its on-commit queue |
signals::SUPPRESS_SIGNALS | no | save_quietly must not silence a job days later |
admin::session::CURRENT_SESSION, CURRENT_CSRF_TOKEN | no | belong to one request |
tenant_log::TENANT | no | a log label for one request |
A value that was never set is not copied as a default: the work sees “no scope”, exactly as its caller did.
A source set by the tenant admin (or audit::with_tenant_source) names a user of that tenant, so it
is recorded only where writes are known to go there (a
tenancy::with_tenant or for_each_tenant pass over it); elsewhere,
the registry included, it reads as system.
§Where it is carried
jobs::InMemoryJobQueuecaptures atdispatch.scheduler::Schedulercaptures atevery(): a tick has no caller, so registration is the hand-off.jobs::pg::PgJobQueuestores it inrustango_jobs.contextatdispatch. A table without that column (a hand-written migration not yet updated) runs jobs with no context, as before.
§What the source does not tell you
A job’s audit row names the enqueuer and nothing else, so it reads identically to one written on the request itself. Recording that it ran deferred needs its own column rather than a prefix on the token, which would break the exact-match filters that read it: #1385.
Structs§
- Task
Context - A snapshot of the ambient context worth carrying into deferred work.