From 5e960b290688206d6f31299dc3631b80f70f0518 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ses=C3=B3stris=20Vieira?= Date: Mon, 2 Oct 2023 11:19:57 -0300 Subject: [PATCH] Cronjob sincronizar participantes Saberes x SIGI. Gertiq #163655 --- sigi/apps/eventos/jobs/__init__.py | 0 sigi/apps/eventos/jobs/daily/__init__.py | 0 .../eventos/jobs/daily/sincroniza_saberes.py | 37 +++++++++++++++++++ sigi/apps/eventos/jobs/hourly/__init__.py | 0 sigi/apps/eventos/jobs/monthly/__init__.py | 0 sigi/apps/eventos/jobs/sample.py | 9 +++++ sigi/apps/eventos/jobs/weekly/__init__.py | 0 sigi/apps/eventos/jobs/yearly/__init__.py | 0 8 files changed, 46 insertions(+) create mode 100644 sigi/apps/eventos/jobs/__init__.py create mode 100644 sigi/apps/eventos/jobs/daily/__init__.py create mode 100644 sigi/apps/eventos/jobs/daily/sincroniza_saberes.py create mode 100644 sigi/apps/eventos/jobs/hourly/__init__.py create mode 100644 sigi/apps/eventos/jobs/monthly/__init__.py create mode 100644 sigi/apps/eventos/jobs/sample.py create mode 100644 sigi/apps/eventos/jobs/weekly/__init__.py create mode 100644 sigi/apps/eventos/jobs/yearly/__init__.py diff --git a/sigi/apps/eventos/jobs/__init__.py b/sigi/apps/eventos/jobs/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/sigi/apps/eventos/jobs/daily/__init__.py b/sigi/apps/eventos/jobs/daily/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/sigi/apps/eventos/jobs/daily/sincroniza_saberes.py b/sigi/apps/eventos/jobs/daily/sincroniza_saberes.py new file mode 100644 index 0000000..6dda84b --- /dev/null +++ b/sigi/apps/eventos/jobs/daily/sincroniza_saberes.py @@ -0,0 +1,37 @@ +from django_extensions.management.jobs import DailyJob +from django.db.models import Q +from django.conf import settings +from django.utils import timezone +from sigi.apps.eventos.models import Evento + + +class Job(DailyJob): + help = "Sincroniza número de inscritos e aprovados com o Saberes." + + def execute(self): + print("Sincronizando número de inscritos e aprovados com o Saberes.") + print(f" Início: {timezone.localtime(): %d/%m/%Y %H:%M:%S}") + + trintadias = timezone.localtime() - timezone.timedelta(days=30) + eventos = Evento.objects.exclude(moodle_courseid=None).filter( + ( + Q(data_sincronizacao=None) + & Q(data_termino__lte=timezone.localtime()) + ) + | ( + Q(data_termino__gte=trintadias) + & Q(data_termino__lte=timezone.localtime()) + ) + ) + + print(f" total de eventos a sincronizar: {eventos.count()}") + + for e in eventos: + try: + e.sincroniza_saberes() + except Evento.SaberesSyncException as err: + print( + f" Erro ao sincronizar evento {e.id}, " + f"com a mensagem '{err.message}'" + ) + print(f" Término: {timezone.localtime(): %d/%m/%Y %H:%M:%S}") diff --git a/sigi/apps/eventos/jobs/hourly/__init__.py b/sigi/apps/eventos/jobs/hourly/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/sigi/apps/eventos/jobs/monthly/__init__.py b/sigi/apps/eventos/jobs/monthly/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/sigi/apps/eventos/jobs/sample.py b/sigi/apps/eventos/jobs/sample.py new file mode 100644 index 0000000..b1ae62c --- /dev/null +++ b/sigi/apps/eventos/jobs/sample.py @@ -0,0 +1,9 @@ +from django_extensions.management.jobs import BaseJob + + +class Job(BaseJob): + help = "My sample job." + + def execute(self): + # executing empty sample job + pass diff --git a/sigi/apps/eventos/jobs/weekly/__init__.py b/sigi/apps/eventos/jobs/weekly/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/sigi/apps/eventos/jobs/yearly/__init__.py b/sigi/apps/eventos/jobs/yearly/__init__.py new file mode 100644 index 0000000..e69de29