Opened 54 minutes ago
#37400 new New feature
Add metadata API to Tasks
| Reported by: | Jake Howard | Owned by: | |
|---|---|---|---|
| Component: | Tasks | Version: | 6.1 |
| Severity: | Normal | Keywords: | |
| Cc: | Jake Howard | Triage Stage: | Unreviewed |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
A TaskResult should have metadata - a writable persistent dict (JSON-compatible) containing additional data about the task, but outside of its arguments.
Proposed API:
my_task.using(metadata={"trace_id": 123}).enqueue(foo=1)would enqueue themy_tasktask with metadata{"trace_id": 123}and argumentsfoo=1.- Metadata could be retrieved using task context
context.metadata - If the
context.metadatais modified, it is saved when a task finishes (successfully or otherwise) - Metadata can be saved within a task using
context.save_metadata()(or.asave_metadata) metadatais always adict, and must be strictly JSON-supported types (as task args and kwargs are currently)- Metadata support is opt-in - backends must set the
supports_metadatafeature and implementsave_metadataand/orasave_metadata - By convention, metadata keys prefixed with
_should not be used by end users. Keys prefixed with_djangoshould be considered reserved by Django and its first-party backends. Backend or library developers are free to use their own narrow-scoped reservd prefixes, so long as they start with_. They may be stored, but are stripped out before being shown by the user, and are ignored during save.
Note:
See TracTickets
for help on using tickets.