From 6705583c899fbada99443d327aa23ce8ee79b589 Mon Sep 17 00:00:00 2001 From: eric Date: Wed, 4 Mar 2020 14:37:40 -0500 Subject: [PATCH] added automation tasks --- core/tasks.py | 6 ++++++ frontend/tasks.py | 17 +++++++++++++++++ settings/common.py | 12 ++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 frontend/tasks.py diff --git a/core/tasks.py b/core/tasks.py index 9d66a3a3..bb466e8e 100644 --- a/core/tasks.py +++ b/core/tasks.py @@ -13,6 +13,7 @@ django imports from django.conf import settings from django.contrib.auth.models import User from django.core.mail import send_mail +from django.core.management import call_command from django.utils.timezone import now from notification.engine import send_all from notification import models as notification @@ -217,3 +218,8 @@ def notify_unclaimed_gifts(): if unclaimed_duration > 0 and unclaimed_duration % 7 == 0 : # first notice in 7 days notification.send_now([gift.acq.user], "purchase_gift_waiting", {'gift':gift}, True) notification.send_now([gift.giver], "purchase_notgot_gift", {'gift':gift}, True) + +@task +def periodic_cleanup(): + call_command('clearsessions') + call_command('cleanupregistration') diff --git a/frontend/tasks.py b/frontend/tasks.py new file mode 100644 index 00000000..1f289576 --- /dev/null +++ b/frontend/tasks.py @@ -0,0 +1,17 @@ +from os.path import join +from datetime import date + +from celery.task import task + +from django.conf import settings +from django.template.loader import get_template, render_to_string + +from .views import InfoPageView + +@task +def save_info_page(): + page_view = InfoPageView() + page = render_to_string(page_view.template_name, context=page_view.get_context_data()) + today = date.today().isoformat() + with open(join(settings.PROJECT_DIR, 'logs', 'metrics-%s.html' % today), 'w') as todays_metrics: + todays_metrics.write(page) diff --git a/settings/common.py b/settings/common.py index e1642988..d0ec26fa 100644 --- a/settings/common.py +++ b/settings/common.py @@ -414,6 +414,18 @@ NOTIFY_UNCLAIMED_GIFTS = { "args": () } +SAVE_INFO_PAGE = { + "task": "regluit.frontend.tasks.save_info_page", + "schedule": crontab(minute=25), + "args": () +} + +PERIODIC_CLEANUP = { + "task": "regluit.core.tasks.periodic_cleanup", + "schedule": crontab( minute=30), + "args": () +} + # by default, in common, we don't turn any of the celerybeat jobs on -- turn them on in the local settings file # set notification queueing on