From f91bb571c8cb970a6b721c4172d84793d9f663d0 Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Sat, 1 Aug 2026 10:50:25 +0200 Subject: [PATCH] use Conf.pub only --- .../teleforma-publish-notify-conferences.py | 21 ++++-------- teleforma/models/core.py | 33 ++++++++++++++++++- teleforma/views/core.py | 2 ++ 3 files changed, 40 insertions(+), 16 deletions(-) diff --git a/teleforma/management/commands/teleforma-publish-notify-conferences.py b/teleforma/management/commands/teleforma-publish-notify-conferences.py index 58159764..84724d56 100644 --- a/teleforma/management/commands/teleforma-publish-notify-conferences.py +++ b/teleforma/management/commands/teleforma-publish-notify-conferences.py @@ -17,7 +17,7 @@ from teleforma.views.core import get_courses import datetime -MINUTES_LOW_RANGE = 5 +MINUTES_LOW_RANGE = 25 MINUTES_HIGH_RANGE = 25 class Logger: @@ -36,6 +36,7 @@ class Logger: self.logger.setLevel(logging.INFO) + class Command(BaseCommand): help = """Publish conferences and notify users when \ conference.date_publish is equal or greater \ @@ -74,30 +75,19 @@ class Command(BaseCommand): now_minus = now - datetime.timedelta(minutes=minute_low_range) now_plus = now + datetime.timedelta(minutes=minute_high_range) - publications = list(Conference.objects.filter( + publications = ConferencePublication.objects.filter( period=period, status=2, notified=False, - streaming=False, date_publish__lte=now_plus, date_publish__gte=now_minus, - )) + list(ConferencePublication.objects.filter( - period=period, - status=2, - notified=False, - date_publish__lte=now_plus, - date_publish__gte=now_minus, - )) + ) logger.logger.info("Starting conference publication process") for publication in publications: - if type(publication) == ConferencePublication: - conference = publication.conference - else: - conference = publication - + conference = publication.conference medias = conference.media.all() if medias: @@ -140,6 +130,7 @@ class Command(BaseCommand): logger.logger.info("Student NOT notified: " + str(student.id)) continue + # staff for user in User.objects.filter(is_staff=True): notify(user, message, url) diff --git a/teleforma/models/core.py b/teleforma/models/core.py index 3447b199..40f73575 100644 --- a/teleforma/models/core.py +++ b/teleforma/models/core.py @@ -693,7 +693,7 @@ class Conference(models.Model): def _notify_live_conference_thread(conference_id): - """Fonction exécutée dans un thread séparé pour notifier la conférence.""" + """Fonction exécutée dans un thread séparé pour notifier la conférence live.""" from django.db import connection from teleforma.models.core import Conference try: @@ -703,6 +703,11 @@ def _notify_live_conference_thread(conference_id): conference.notify_live_sync() conference.notified_live = True conference.save() + if not conference.streaming and not conference.notified: + logger.info("notify conference publication on secondary thread " + str(conference.id)) + conference.notify_live_sync() + conference.notified = True + conference.save() except Conference.DoesNotExist: pass except Exception: @@ -711,11 +716,36 @@ def _notify_live_conference_thread(conference_id): connection.close() +def _notify_conference_publication_thread(conference_id): + """Fonction exécutée dans un thread séparé pour notifier la publication de la conférence.""" + from django.db import connection + from teleforma.models.core import Conference + try: + conference = Conference.objects.get(id=conference_id) + if not conference.streaming and not conference.notified: + logger.info("notify conference publication on secondary thread " + str(conference.id)) + conference.notify_live_sync() + conference.notified = True + conference.save() + + except Conference.DoesNotExist: + pass + except Exception: + pass + finally: + connection.close() + + + def notif_live_conference_thread(sender, instance, *args, **kwargs): if instance.streaming and not instance.notified_live: thread = threading.Thread(target=_notify_live_conference_thread, args=(instance.id,)) thread.daemon = True thread.start() + if not instance.streaming and not instance.notified: + thread = threading.Thread(target=_notify_conference_publication_thread, args=(instance.id,)) + thread.daemon = True + thread.start() def notif_live_conference_sync(sender, instance, *args, **kwargs): @@ -724,6 +754,7 @@ def notif_live_conference_sync(sender, instance, *args, **kwargs): instance.notified_live = True instance.save() + post_save.connect(notif_live_conference_thread, sender=Conference) diff --git a/teleforma/views/core.py b/teleforma/views/core.py index 19069e06..948a5ac2 100644 --- a/teleforma/views/core.py +++ b/teleforma/views/core.py @@ -151,12 +151,14 @@ def get_course_conferences(period, course, course_type, status_min=3): if period.corrections_from and course.corrections_shared and course_type.id == settings.CORRECTIONS_COURSE_TYPE_ID: periods.append(period.corrections_from) + # get conference publications publications = ConferencePublication.objects.filter( period__in=periods, conference__course=course, conference__course_type=course_type, status__gte=status_min).distinct() + for publication in publications: conferences.append(publication.conference) already_added.add(publication.conference.id) -- 2.47.3