Django和Celery:如何使用Celery安排作业只运行一次(类似于linux中的“at”命令)?

时间:2021-02-23 14:38:54

I looked at django-celery tutorial and I think it will really help me running the background tasks without letting the users to wait. However, I have a specific requirement in the program such that when user enters a date, django should be able to do the scheduling and defer the execution to a later time. I have used at program before but it gives a lot of permission issues. But when I read the documentation for Celery, I can only see that Celery supports cron like tasks called @periodic_task. I'm sure that it also provides at like mechanism, but I couldn't find any documentation. Can anybody point me to some resources or simply tell me how to achieve that? Thanks.

我查看了django-celery教程,我认为这将帮助我在不让用户等待的情况下运行后台任务。但是,我在程序中有一个特定的要求,当用户输入日期时,django应该能够进行调度并将执行推迟到以后的时间。我之前在程序中使用过,但它提供了很多权限问题。但是当我阅读Celery的文档时,我只能看到Celery支持类似于@periodic_task的cron任务。我确信它也提供了类似的机制,但我找不到任何文档。任何人都能指出一些资源或只是告诉我如何实现这一目标吗?谢谢。

2 个解决方案

#1


10  

The docs state that you can schedule tasks to execute at a specific time, using the eta argument.

文档声明您可以使用eta参数安排任务在特定时间执行。

#2


3  

You can supply the countdown or ETA argument to the apply_async() function. By doing so, you can define the earliest time that the task is gonna be executed, but not the exact one (it depends on your queue). For more details see here.

您可以向apply_async()函数提供倒计时或ETA参数。通过这样做,您可以定义任务将被执行的最早时间,但不是确切的一个(它取决于您的队列)。有关详细信息,请参阅此处

#1


10  

The docs state that you can schedule tasks to execute at a specific time, using the eta argument.

文档声明您可以使用eta参数安排任务在特定时间执行。

#2


3  

You can supply the countdown or ETA argument to the apply_async() function. By doing so, you can define the earliest time that the task is gonna be executed, but not the exact one (it depends on your queue). For more details see here.

您可以向apply_async()函数提供倒计时或ETA参数。通过这样做,您可以定义任务将被执行的最早时间,但不是确切的一个(它取决于您的队列)。有关详细信息,请参阅此处