Add advisory lock to send_notifications
parent
ae558ad471
commit
bc2f1b57df
|
@ -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")
|
||||||
|
|
Loading…
Reference in New Issue