Skip to content Skip to sidebar Skip to footer

Celery: Different Settings For Task_acks_late Per Worker / Add Custom Option To Celery

This question is a follow up of django + celery: disable prefetch for one worker, Is there a bug? I had a problem with celery (see the question that I follow up) and in order to re

Solution 1:

One possible solution here is to provide acks_late=True as an argument of the shared_task decorator, given your code from the prior question:

@shared_task(acks_late=True)deftask_fast(delay=0.1):
    logger.warning("fast in")
    time.sleep(delay)
    logger.warning("fast out")

UPD. I haven't got task_acks_late to be set using this approach, but you could add a command line argument as follows.

You've already linked to a solution. I can't see any django specifics here, just put the parser.add_argument code to where you have defined your app, given your code from the prior question, you would have something like this:

app = Celery("miniclry", backend="rpc", broker="pyamqp://")
app.config_from_object('django.conf:settings', namespace='CELERY')

defadd_worker_arguments(parser):
    parser.add_argument('--late-ack', default=False)

app.user_options['worker'].add(add_worker_arguments)

Then you could access your argument value in celeryd_init signal handler

@celeryd_init.connectdefconfigure_worker(sender=None, conf=None, options=None, **kwargs):
    conf.task_acks_late = options.get('late-ack') # get custom argument value from options

Post a Comment for "Celery: Different Settings For Task_acks_late Per Worker / Add Custom Option To Celery"