From e65eed1af199ccaf7bc18be94adb3c54ae74f031 Mon Sep 17 00:00:00 2001 From: Maxim Kolyubyakin Date: Tue, 29 Nov 2022 18:37:54 +0100 Subject: [PATCH] LITE-25903 `cqrs_sync` is more DB failure tolerant `close_old_connections` is called when there is Exception --- dj_cqrs/management/commands/cqrs_sync.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/dj_cqrs/management/commands/cqrs_sync.py b/dj_cqrs/management/commands/cqrs_sync.py index 3c4d7a2..4cd6158 100644 --- a/dj_cqrs/management/commands/cqrs_sync.py +++ b/dj_cqrs/management/commands/cqrs_sync.py @@ -9,6 +9,7 @@ from django.core.exceptions import FieldError from django.core.management.base import BaseCommand, CommandError +from django.db import close_old_connections import ujson @@ -69,6 +70,7 @@ def handle(self, *args, **options): for qs_ in batch_qs(model.relate_cqrs_serialization(qs), batch_size=batch_size): ts = time.time() cs = counter + for instance in qs_: counter += 1 try: @@ -78,6 +80,7 @@ def handle(self, *args, **options): print('\nSync record failed for pk={0}: {1}: {2}'.format( instance.pk, type(e).__name__, str(e), )) + close_old_connections() if progress: rate = (counter - cs) / (time.time() - ts)