根据用户输入使用 django-celery 安排任务
我正在使用 django 构建一个报告门户。在此门户中,我需要让用户能够安排报告定期运行。我一直在研究 django-celery 并了解您可以使用 periodical_task 装饰器来安排重复发生的任务,但在所有示例中我都看到 cron 计划信息被硬编码到装饰器中。
@periodic_task(run_every=crontab(hours=7, minute=30, day_of_week="mon"))
有没有一种方法使用 django-celery 根据用户的输入动态地安排重复发生的任务?
例如,用户使用表单来选择他们想要运行的报表,提供报表所需的所有参数以及他们想要运行报表的时间表。处理完表单后,是否可以调用方法或函数来将 run_report 任务添加到计划中?如果是这样,有没有办法检索数据库中存储的所有当前时间表以便显示它们?
I am building a reporting portal using django. In this portal I need to give users the ability to schedule reports to run on a reoccurring basis. I have been researching django-celery and understand that you can use the periodic_task decorator to schedule a reoccurring task but in all the examples I have seen the cron schedule information is hard coded into the decorator.
@periodic_task(run_every=crontab(hours=7, minute=30, day_of_week="mon"))
Is there a way using django-celery to schedule a reoccurring task dynamically based on input from a user?
For example, a user uses a form to select the report they want run, provide all the parameters required by the report and the schedule when they want the report run on. Once I have processed the form is there a method or function I can call to add a run_report task to a schedule? If so is there a way to retrieve all the current schedules stored in the database so they can be displayed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在管理界面中查看 djcelery:
http://localhost:8000/admin/djcelery/
尝试是否可以构建所需的任务设置那里(使用 crontabs/间隔/定期任务)
如果是的话,您很有可能可以快速建立起来。
Tak a look at djcelery in the admin-interface:
http://localhost:8000/admin/djcelery/
Try if you can build the required task-setup there (using crontabs/intervals/periodic tasks)
If yes there is a big chance that you can build this up quickly..
http://celery.readthedocs.org/en/latest/userguide/calling.html
例如:-
。
从现在起 10 秒后执行。
从现在起 10 秒后执行,使用 eta 指定
从现在起一分钟内执行,但在 2 分钟后过期。
http://celery.readthedocs.org/en/latest/userguide/calling.html
eg:-
.
executes 10 seconds from now.
executes 10 seconds from now, specifed using eta
executes in one minute from now, but expires after 2 minutes.
覆盖模型中的保存方法。每当用户输入喜欢启动流程/任务时,他都会修改触发任务启动的模型。
your_app/models.py:
your_app/tasks.py
Override your save method in models. Whenever user enters likes to start a process/task, he will modify the model which triggers the task to start.
your_app/models.py:
your_app/tasks.py