diff --git a/supervisor.d/expiration.conf b/supervisor.d/expiration.conf index 53248aa..ddfca10 100644 --- a/supervisor.d/expiration.conf +++ b/supervisor.d/expiration.conf @@ -1 +1,14 @@ # Move notice to expired notices +[program:expiration] +command=python -u /omniport/apps/noticeboard/supervisor.d/expired_notices.py +directory=/omniport/apps/noticeboard/supervisor.d +stdout_logfile=/web_server_logs/supervisord_logs/celery-%(ENV_SITE_ID)s-stdout.log +stdout_logfile_maxbytes=1048576 +stdout_logfile_backups=32 + +stderr_logfile=/web_server_logs/supervisord_logs/celery-%(ENV_SITE_ID)s-stderr.log +stderr_logfile_maxbytes=1048576 +stderr_logfile_backups=32 +redirect_stderr=true +autostart=true +autorestart=true \ No newline at end of file diff --git a/supervisor.d/expired_notices.py b/supervisor.d/expired_notices.py new file mode 100644 index 0000000..1516bf5 --- /dev/null +++ b/supervisor.d/expired_notices.py @@ -0,0 +1,35 @@ +import os +import time +import django +import swapper +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "omniport.settings") +django.setup() + +from noticeboard.models import Notice, ExpiredNotice +from datetime import datetime, timedelta +from threading import Timer + +x=datetime.today() +y = x.replace(day=x.day, hour=1, minute=0, second=0, microsecond=0) + timedelta(days=1) +delta_t=y-x +secs=delta_t.total_seconds() +def exp_func(): + all_notices = Notice.objects.filter(is_draft=False) + for notice in all_notices: + if notice.notice_has_expired: + expired_notice = ExpiredNotice.objects.create( + notice_id = notice.id, + uploader = notice.uploader, + title = notice.title, + content = notice.content, + banner = notice.banner, + expiry_date = notice.expiry_date, + is_important = notice.is_important, + is_public = notice.is_public, + is_edited = notice.is_edited, + ) + print(expired_notice) + notice.delete() + +t = Timer(secs, exp_func) +t.start() \ No newline at end of file