用Chronos取代Celerybeat [英] Replacing Celerybeat with Chronos

查看:59
本文介绍了用Chronos取代Celerybeat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

计时有多成熟?是像celery-beat这样的调度程序的可行替代方案吗?

How mature is Chronos? Is it a viable alternative to scheduler like celery-beat?

现在,我们的日程安排实施了定期的心跳"任务,该任务检查未决"事件并在事件过期时将其触发.我们使用 python-dateutil 的规则进行定义.

Right now our scheduling implements a periodic "heartbeat" task that checks of "outstanding" events and fires them if they are overdue. We are using python-dateutil's rrule for defining this.

我们正在寻找这种方法的替代方法,并且 Chronos 似乎是一种非常吸引人的替代方法:1)它将减轻必要性要使用心跳计划任务,2)支持ISO 8601格式的RESTful事件提交,3)具有有用的管理界面,4)可扩展.

We are looking at alternatives to this approach, and Chronos seems a very attactive alternative: 1) it would mitigate the necessity to use a heartbeat schedule task, 2) it supports RESTful submission of events with ISO8601 format, 3) has a useful interface for management, and 4) it scales.

关键的要求是调度需要可以从Web Interface即时配置.这就是为什么不能立即使用celerybeat的内置计划.

The crucial requirement is that scheduling needs to be configurable on the fly from the Web Interface. This is why can't use celerybeat's built-in scheduling out of the box.

我们要切换到Chronos来射击自己吗?

Are we going to shoot ourselves in the foot by switching over to Chronos?

推荐答案

This SO has solutions to your dynamic periodic task problem. It's not the accepted answer at the moment:

 from djcelery.models import PeriodicTask, IntervalSchedule
 from datetime import datetime

 class TaskScheduler(models.Model):

     periodic_task = models.ForeignKey(PeriodicTask)

     @staticmethod
     def schedule_every(task_name, period, every, args=None, kwargs=None):
     """ schedules a task by name every "every" "period". So an example call would be:
          TaskScheduler('mycustomtask', 'seconds', 30, [1,2,3]) 
          that would schedule your custom task to run every 30 seconds with the arguments 1 ,2 and 3 passed to the actual task. 
     """
         permissible_periods = ['days', 'hours', 'minutes', 'seconds']
         if period not in permissible_periods:
             raise Exception('Invalid period specified')
         # create the periodic task and the interval
         ptask_name = "%s_%s" % (task_name, datetime.datetime.now()) # create some name for the period task
         interval_schedules = IntervalSchedule.objects.filter(period=period, every=every)
         if interval_schedules: # just check if interval schedules exist like that already and reuse em
             interval_schedule = interval_schedules[0]
         else: # create a brand new interval schedule
             interval_schedule = IntervalSchedule()
             interval_schedule.every = every # should check to make sure this is a positive int
             interval_schedule.period = period 
             interval_schedule.save()
         ptask = PeriodicTask(name=ptask_name, task=task_name, interval=interval_schedule)
         if args:
             ptask.args = args
         if kwargs:
             ptask.kwargs = kwargs
         ptask.save()
         return TaskScheduler.objects.create(periodic_task=ptask)

     def stop(self):
         """pauses the task"""
         ptask = self.periodic_task
         ptask.enabled = False
         ptask.save()

     def start(self):
         """starts the task"""
         ptask = self.periodic_task
         ptask.enabled = True
         ptask.save()

     def terminate(self):
         self.stop()
         ptask = self.periodic_task
         self.delete()
         ptask.delete()

我还没有使用 djcelery ,但是据推测具有动态周期性任务的管理界面.

I haven't used djcelery yet, but it supposedly has an admin interface for dynamic periodic tasks.

这篇关于用Chronos取代Celerybeat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆