PreconditionFailed with scheduled Celery task

I have a model that has a state field which can be draft or published, and has a scheduled_publish_time datetime field which allows scheduling its publishing.

The user specifies a datetime at which they want the model to be published, and a celery task is scheduled using apply_async with the eta argument set to that value.

The problem is, if the datetime is set too far in the future, I get this error eventually:

amqp.exceptions.PreconditionFailed: (0, 0): (406) PRECONDITION_FAILED - delivery acknowledgement on channel 1 timed out. Timeout value used: 1800000 ms. This timeout value can be configured, see consumers doc guide to learn more

I am using RabbitMQ as the broker for celery.

I googled it and it seems it’s a common issue. Some suggest just increasing the timeout, but I am not sure it’s a good idea. Ideally, I would allow scheduling these tasks very far in the future, possibly months ahead, so I don’t think putting a huge timeout is the wisest thing.

Is there a better way to handle this issue?

My suggestion in this case then is to use Celery Beat and schedule your task as a one-time task to execute at the desired time.

Side note: See the “Warning” box at Calling Tasks — Celery 5.2.7 documentation
So it’s not just “some people” recommending this, this is what the documented solution is.

Hi @samul-1 ,
You are right; scheduling tasks very far in the future is not recommended.
Mor details about it you can read from that comment also.