Skip to content

Commit

Permalink
Add supervisor script for expired notices
Browse files Browse the repository at this point in the history
  • Loading branch information
carpecodeum committed Oct 17, 2020
1 parent 503ebe0 commit 2887890
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
13 changes: 13 additions & 0 deletions supervisor.d/expiration.conf
Original file line number Diff line number Diff line change
@@ -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
35 changes: 35 additions & 0 deletions supervisor.d/expired_notices.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 2887890

Please sign in to comment.