Skip to content

Commit 2aee95e

Browse files
tinylambdaauvipy
authored andcommitted
No transaction need here. and Avoid catching exceptions inside atomic… (#176)
* No transaction need here. and Avoid catching exceptions inside atomic! refer to: https://docs.djangoproject.com/en/2.1/topics/db/transactions/#controlling-transactions-explicitly * No transaction need here. and Avoid catching exceptions inside atomic! refer to: https://docs.djangoproject.com/en/2.1/topics/db/transactions/#controlling-transactions-explicitly * No transaction need here. and Avoid catching exceptions inside atomic! refer to: https://docs.djangoproject.com/en/2.1/topics/db/transactions/#controlling-transactions-explicitly optimization: only retry for the failed updates
1 parent 1aff35b commit 2aee95e

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

django_celery_beat/schedulers.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -252,19 +252,20 @@ def reserve(self, entry):
252252
def sync(self):
253253
info('Writing entries...')
254254
_tried = set()
255+
_failed = set()
255256
try:
256257
close_old_connections()
257-
with transaction.atomic():
258-
while self._dirty:
259-
try:
260-
name = self._dirty.pop()
261-
_tried.add(name)
262-
self.schedule[name].save()
263-
except (KeyError, ObjectDoesNotExist):
264-
pass
258+
259+
while self._dirty:
260+
name = self._dirty.pop()
261+
try:
262+
self.schedule[name].save()
263+
_tried.add(name)
264+
except (KeyError, ObjectDoesNotExist) as exc:
265+
_failed.add(name)
265266
except (DatabaseError, InterfaceError) as exc:
266-
# retry later
267-
self._dirty |= _tried
267+
# retry later, only for the failed ones
268+
self._dirty |= _failed
268269
logger.exception('Database error while sync: %r', exc)
269270

270271
def update_from_dict(self, mapping):

0 commit comments

Comments
 (0)