Hi,
I got Race conditions errors, and sometimes, when I edit a schedule, bunch of other tasks are executed without respecting their schedules.
Reading the code, I think it could be optimized but I'm not sure enough, I post it here if someone reads me ;)
We have this in MongoSchedulers:
def get_from_database(self):
self.sync()
d = {}
for doc in self.Model.objects.filter(enabled=True):
d[doc.name] = self.Entry(doc)
return d
@property
def schedule(self):
if self.requires_update():
self._schedule = self.get_from_database()
self._last_updated = datetime.datetime.now()
return self._schedule
def sync(self):
logger.debug('Writing entries...')
for entry in self._schedule.values():
entry.save()
While in beat.py from celery, at each tick, we verify difference between previous schedule and new one, so we trigger a get_from_database quiet often because the require_upates refresh every 5sec, the same as tick time interval.
So every 5 sec, we sync, we fetch from database, and once finished, we look if we need to sync again and probably we do.
So we could let beat.py :
def should_sync(self):
return (
(not self._last_sync or
(time.monotonic() - self._last_sync) > self.sync_every) or
(self.sync_every_tasks and
self._tasks_since_sync >= self.sync_every_tasks)
)
decide if we should sync :
@property
def schedule(self):
return self._schedule
def sync(self):
logger.debug('Writing entries...')
for entry in self._schedule.values():
entry.save()
self._schedule = {}
for doc in self.Model.objects.filter(enabled=True):
self._schedule[doc.name] = self.Entry(doc)
I need to test it.
Hi,
I got Race conditions errors, and sometimes, when I edit a schedule, bunch of other tasks are executed without respecting their schedules.
Reading the code, I think it could be optimized but I'm not sure enough, I post it here if someone reads me ;)
We have this in MongoSchedulers:
While in beat.py from celery, at each tick, we verify difference between previous schedule and new one, so we trigger a get_from_database quiet often because the require_upates refresh every 5sec, the same as tick time interval.
So every 5 sec, we sync, we fetch from database, and once finished, we look if we need to sync again and probably we do.
So we could let beat.py :
decide if we should sync :
I need to test it.