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