3👍
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)
def task_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')
def add_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.connect
def configure_worker(sender=None, conf=None, options=None, **kwargs):
conf.task_acks_late = options.get('late-ack') # get custom argument value from options
Source:stackexchange.com