-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add supervisor script for expired notices
- Loading branch information
1 parent
503ebe0
commit 2887890
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |