1

I am quite new to Celery. Here is my code for configuring Celery Beat.

app.conf.beat_schedule = {
    # EMAILS
    'send-feedback-mail-every-2-weeks': {
        'task': 'stocks.tasks.send_ask_feedback',
        'schedule': crontab(day_of_week=6),
    },
    'get-terminal-data-frequently': {
        'task': 'stocks.tasks.get_terminal_data_func',
        'schedule': crontab(minute="*"),
    },
    # NEWS
    'get-newyorktimes-api': {
        'task': 'stocks.tasks.get_news_nyt',
        'schedule': crontab(minute="*"),
    },
}

I am wondering how to query the associated tasks for the periodic task get-newyorktimes-api in my view to pass the result of each into the context. I tried:

context['celery'] = TaskResult.objects.filter(periodic_task_name='get-newyorktimes-api')

It returned an empty queryset even though I've run the task successfully multiple times. Where is my fault in this Task filter?

1 Answer 1

0

Starting from Celery 5.5.3 and newer, the periodic_task_name argument should no longer be passed directly to apply_async.
Instead, it needs to be included in the task headers, for example:

task.apply_async(headers={"periodic_task_name": "task_name"})

This change aligns with the updated task serialization behavior in newer Celery versions.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.