[backport] Add advisory lock to send_notifications

remotes/origin/3.4.0rc
Jesús Espino 2018-02-07 10:48:04 +01:00
parent 0903bfa6de
commit ee3e94d2e7
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.services import send_sync_notifications
from django_pglocks import advisory_lock
class Command(BaseCommand):
def handle(self, *args, **options):
with advisory_lock("send-notifications-command", wait=False) as acquired:
if acquired:
qs = HistoryChangeNotification.objects.all()
for change_notification in iter_queryset(qs, itersize=100):
try:
send_sync_notifications(change_notification.pk)
except HistoryChangeNotification.DoesNotExist:
pass
else:
print("Other process already running")