def handle(self, *args, **options):
"""
Always try to grab the celerybeat lock, and if you get it start
celerybeat. If not, stop any instances of celerybeat.
Every instance of this script has a unique ID stored in memory for the
duration of the process. If the process dies, it'll get a new UUID.
While it's down, another process may pick up the lock and start its own
celerybeat instance.
We assume there is one instance of this script and one instance of
celerybeat (both running inside supervisor) on each machine in the
cluster.
"""
my_id = str(uuid.uuid4())
environment = os.getenv("CELERY_DEFAULT_QUEUE", "none")
lock_name = '%s:celerybeat' % environment
while True:
if Lock.grab(lock_name, my_id, ttl=300):
envoy.run('sudo supervisorctl start celerybeat')
syslog.syslog("I have the lock: %s -> %s" % (lock_name, my_id))
else:
syslog.syslog("Can't grab lock: %s -> %s" % (lock_name, my_id))
envoy.run('sudo supervisorctl stop celerybeat')
time.sleep(240)
celerystick.py 文件源码
python
阅读 24
收藏 0
点赞 0
评论 0
评论列表
文章目录