我正在尝试从tornado应用程序界面启动和停止芹菜周期性任务。
例如,假设有两个任务:A和B。我希望用户能够选择一个HTML表单的周期性(每分钟,每个月,每5分钟等),并单击任务A的start。用户可以做同样的任务B,然后返回到一个页面上有一个按钮,以停止任务A和/或任务B随时他想要的。
我浏览了很多关于这个话题的stackoverflow问题,但他们都没有回答这个简单的问题。
到目前为止,我的tornado应用程序处理简单的芹菜工人没有任何问题,我面临的问题是periodic tasks。(https://docs.celeryproject.org/en/latest/reference/celery.html#celery.Celery.on_after_configure)
continuous_monitoring_worker.py:
continuous_tracking_worker_app.conf.timezone = 'Europe/London'
@continuous_tracking_worker_app.on_after_configure.connect
def setup_periodic_tasks(sender, **kwargs):
print('OK inside setup periodic tasks ...')
sender.add_periodic_task(10.0, test.s('Hello World'), name='add every 10')
# In case I want to stop the task later
#time.sleep(35)
#print('beat_schedule = {}'.format(continuous_tracking_worker_app.conf.beat_schedule))
#del continuous_tracking_worker_app.conf.beat_schedule['add every 10']
@continuous_tracking_worker_app.task
def test(name):
print('Periodic task called, name = {}'.format(name))使用这段代码,我解决了以下问题:当我启动应用程序时,它每10秒启动一次任务(我猜是因为@continuous_tracking_worker_app.on_after_configure.connect装饰器)。但我希望任务是从界面按需启动的(在我的tornado视图文件的后端通过调用setup_periodic_tasks(continuous_tracking_worker_app),而不是在启动tornado应用程序时!)
发布于 2019-08-11 23:01:45
芹菜节拍不能这么做。
您可以考虑使用使其成为可能的Celery Redbeat。
发布于 2020-12-26 04:20:31
芹菜节拍可以做到这一点。
只需按照here, (go to the expiration tab)的说明设置expires变量
https://stackoverflow.com/questions/57441699
复制相似问题