Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8860603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:17:40+00:00 2026-06-14T15:17:40+00:00

I use celery in my application to run periodic tasks. Let’s see simple example

  • 0

I use celery in my application to run periodic tasks. Let’s see simple example below

from myqueue import Queue
@perodic_task(run_every=timedelta(minutes=1))
def process_queue():
    queue = Queue()
    uid, questions = queue.pop()
    if uid is None:
        return

    job = group(do_stuff(q) for q in questions)
    job.apply_async()

def do_stuff(question):
    try:
        ...
    except:
        ...
        raise

As you can see in the example above, i use celery to run async task, but (since it’s a queue) i need to do queue.fail(uid) in case of exception in do_stuff or queue.ack(uid) otherwise. In this situation it would be very clear and usefull to have some callback from my task in both cases – on_failure and on_success.

I saw some documentation, but never seen practices of using callbacks with apply_async. Is it possible to do that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T15:17:41+00:00Added an answer on June 14, 2026 at 3:17 pm

    Subclass the Task class and overload the on_success and on_failure functions:

    from celery import Task
    
    
    class CallbackTask(Task):
        def on_success(self, retval, task_id, args, kwargs):
            '''
            retval – The return value of the task.
            task_id – Unique id of the executed task.
            args – Original arguments for the executed task.
            kwargs – Original keyword arguments for the executed task.
            '''
            pass
            
        def on_failure(self, exc, task_id, args, kwargs, einfo):
            '''
            exc – The exception raised by the task.
            task_id – Unique id of the failed task.
            args – Original arguments for the task that failed.
            kwargs – Original keyword arguments for the task that failed.
            '''
            pass
    

    Use:

    @celery.task(base=CallbackTask)  # this does the trick
    def add(x, y):
        return x + y
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm attempting to use Celery with the RabbitMQ backend to run asynchronous background tasks
I need in my django project run long tasks. Desided to use celery with
I use: Celery Django-Celery RabbitMQ I can see all my tasks in the Django
I'm trying to use the methods of class as the django-celery tasks, marking it
I'm going to use Celery to manage tasks in cluster. There will be one
How can I use two different celery project which consumes messages from single RabbitMQ
I use Celery to run web spiders which crawl some data, and after that
I'm trying create a simple background periodic task using Django-Celery-RabbitMQ combination. I installed Django
I'm trying to use the AbortableTask feature of Celery but the documentation example doesn't
I am using celery and i want to use the max-tasks-per-child-setting because some of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.