Skip to content

Add Celery Task shadow_name Property #468

Open
@andreangelucci

Description

@andreangelucci

Celery tasks have a property called shadow_name that helps identify task execution in logs, as executions typically share the same task names.

After running a Celery task, we can monitor the execution with the TaskResult object. However, when there are multiple executions of the same task that differ only by their arguments, identification becomes challenging.

Would it be feasible to add a shadow_name property to the TaskResult model and enable filtering through Django admin? Alternatively, we could prioritize the shadow name as the task_name if it has been defined.

Shadow name example:

def shadow_name(task, args, kwargs, options):
    return f"sleep_{args[0]}_seconds"

@shared_task(name='sleep-example', shadow_name=shadow_name)
def sleep_example(seconds):
    sleep(seconds)

After running sleep_example.delay(15), we can see:

Image

Image

Image

Image

Image

Celery documentation:
https://docs.celeryq.dev/en/stable/reference/celery.app.task.html#celery.app.task.Task.shadow_name

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions