You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Aug 24, 2024. It is now read-only.
The schedule property, which is accessed by beat internally will update this local copy periodically via get_from_database().
However, get_from_database() calls sync() first before updating the dictionary:
If any Document is deleted from the PeriodicTask-Colleciton this will cause a SaveConditionError to be raised during the next get_from_database()-call. Mongoengine raises this error if an update did not update any documents (this is achieved by checking n_modified). This is always the case because the local copy is saved before fetching updates (even if its counterpart on the database no longer exists). This also causes similar race conditions when updating documents in the PeriodicTask-Collection (changes are sometimes overridden by the local copy).
Maybe the local copy should not be modified at all and therefore never be saved to the database. Instead it should only be periodically updated to avoid too many database requests.
Variables like total_run_count could be updated via atomic update so no race conditions occur.
The text was updated successfully, but these errors were encountered:
classMongodbScheduleEntry(ScheduleEntry):
"""Schedule entry that does not update total_run_count, last_run_at and run_immediately during save"""defsave(self):
"""Save changes"""try:
self._task.save(save_condition={})
exceptExceptionasexc:
get_logger(__name__).exception("Exception during save", exc_info=exc)
classMongoScheduler(Scheduler):
@propertydefschedule(self):
"""The current schedule"""returnself._scheduledefsync(self):
"""Synchronize schedule"""# update total_run_count, last_run_at and run_immediately of all docs in the dbfork, entryinself._schedule.items():
update= {}
ifentry.total_run_count>entry._task.total_run_count:
update["total_run_count"] =entry.total_run_countifentry.last_run_atandentry._task.last_run_atandentry.last_run_at>entry._task.last_run_at:
update["last_run_at"] =entry.last_run_atifentry._task.run_immediately:
update["run_immediately"] =Falseifupdate:
try:
entry._task._get_collection().update_one(fiter={"_id": entry._task.id}, update={})
exceptExceptionasexc:
get_logger(__name__).exception("Exception during sync", exc_info=exc)
# update _scheduleself._schedule= {doc.name: self.Entry(doc) fordocinself.Model.objects}
This will update the necessary fields using an atomic update before fetching the new version of all schedule entries from the database. update_one will fail silently if a document with the given id does not exist.
Use beat_max_loop_interval and beat_sync_every to configure when sync should occur.
I can create a PR for this if wanted.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Currently the scheduler tries to save all entries in its local copy of the schedule to the database in its
sync()
-method:The
schedule
property, which is accessed by beat internally will update this local copy periodically viaget_from_database()
.However,
get_from_database()
callssync()
first before updating the dictionary:If any Document is deleted from the
PeriodicTask
-Colleciton this will cause aSaveConditionError
to be raised during the nextget_from_database()
-call. Mongoengine raises this error if an update did not update any documents (this is achieved by checkingn_modified
). This is always the case because the local copy is saved before fetching updates (even if its counterpart on the database no longer exists). This also causes similar race conditions when updating documents in thePeriodicTask
-Collection (changes are sometimes overridden by the local copy).Maybe the local copy should not be modified at all and therefore never be saved to the database. Instead it should only be periodically updated to avoid too many database requests.
Variables like
total_run_count
could be updated via atomic update so no race conditions occur.The text was updated successfully, but these errors were encountered: