This question already has an answer here:
这个问题在这里已有答案:
- Django - Set Up A Scheduled Job? 20 answers
- Django - 设置预定的工作? 20个答案
Some tuples in my database need to be erased after a given time. I need my django app to check if the rows have expired.
我的数据库中的一些元组需要在给定时间后删除。我需要我的django应用程序来检查行是否已过期。
While I can definitely write the function, how do I make Django run at everyday at a fixed time?
虽然我绝对可以编写这个函数,但是如何让Django在固定时间每天运行?
I have heard about Task Queues like Celery. Are they too much powerful for this? Is their anything simpler? May be something build-in?
我听说过像芹菜这样的任务队列。他们太强大了吗?他们的事情更简单吗?可能是内置的东西?
2 个解决方案
#1
2
Use a simple cron job to trigger a custom Django management command.
使用简单的cron作业来触发自定义Django管理命令。
#2
-1
Use a threading.Thread
to schedule a continuous event loop. In your thread, use time.sleep
to create a gap before the next occurrence of the event.
使用threading.Thread来安排连续的事件循环。在您的线程中,使用time.sleep在下一次事件发生之前创建间隙。
#1
2
Use a simple cron job to trigger a custom Django management command.
使用简单的cron作业来触发自定义Django管理命令。
#2
-1
Use a threading.Thread
to schedule a continuous event loop. In your thread, use time.sleep
to create a gap before the next occurrence of the event.
使用threading.Thread来安排连续的事件循环。在您的线程中,使用time.sleep在下一次事件发生之前创建间隙。