import datetime
-MINUTES_LOW_RANGE = 5
+MINUTES_LOW_RANGE = 25
MINUTES_HIGH_RANGE = 25
class Logger:
self.logger.setLevel(logging.INFO)
+
class Command(BaseCommand):
help = """Publish conferences and notify users when \
conference.date_publish is equal or greater \
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:
logger.logger.info("Student NOT notified: " + str(student.id))
continue
+ # staff
for user in User.objects.filter(is_staff=True):
notify(user, message, url)
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:
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:
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):
instance.notified_live = True
instance.save()
+
post_save.connect(notif_live_conference_thread, sender=Conference)
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)