Answer the question
In order to leave comments, you need to log in
How to start a Celery task with a time delay?
I have a Django model that has an is_activated field. When a new model object is created, is_activated is automatically set to False. In order for this field to become True, the user must fulfill a certain condition within 20 minutes. If within 20 minutes the user has not fulfilled this condition, delete the account.
Whether it is possible to set a timer for a task to delay the execution of the task. Those. queue the task only 20 minutes after saving the model object to check is_activated.
Or is it better to run the task every n-seconds and check the creation time of the model object?
Or are there better solutions to this problem?
Answer the question
In order to leave comments, you need to log in
And I think it's better to use regular tasks with a delay in time:
@app.task
def main(id):
pass
main.apply_async(kwargs={"id": id}, countdown=20 * 60)
Add the expired_at field and use it to block attempts to log in after it expires. And you can clean accounts using cron at least once a minute
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question