Add advisory lock to send_notifications

remotes/origin/release/3.1.1
Jesús Espino 2018-02-07 10:48:04 +01:00
parent ae558ad471
commit bc2f1b57df
1 changed files with 12 additions and 6 deletions

View File

@ -23,12 +23,18 @@ from taiga.base.utils.iterators import iter_queryset
from taiga.projects.notifications.models import HistoryChangeNotification from taiga.projects.notifications.models import HistoryChangeNotification
from taiga.projects.notifications.services import send_sync_notifications from taiga.projects.notifications.services import send_sync_notifications
from django_pglocks import advisory_lock
class Command(BaseCommand): class Command(BaseCommand):
def handle(self, *args, **options): def handle(self, *args, **options):
with advisory_lock("send-notifications-command", wait=False) as acquired:
if acquired:
qs = HistoryChangeNotification.objects.all() qs = HistoryChangeNotification.objects.all()
for change_notification in iter_queryset(qs, itersize=100): for change_notification in iter_queryset(qs, itersize=100):
try: try:
send_sync_notifications(change_notification.pk) send_sync_notifications(change_notification.pk)
except HistoryChangeNotification.DoesNotExist: except HistoryChangeNotification.DoesNotExist:
pass pass
else:
print("Other process already running")