51 lines
2 KiB
Python
Executable file
51 lines
2 KiB
Python
Executable file
#!/usr/bin/env python
|
|
|
|
# This script requires that the proper virtual python environment has been
|
|
# invoked before start
|
|
|
|
import datetime
|
|
import os
|
|
import sys
|
|
import syslog
|
|
|
|
# boilerplate
|
|
basedir = os.path.abspath(os.path.join(os.path.dirname(__file__), "../.."))
|
|
sys.path = [ basedir ] + sys.path
|
|
os.environ["DJANGO_SETTINGS_MODULE"] = "ietf.settings"
|
|
|
|
syslog.openlog(os.path.basename(__file__), syslog.LOG_PID, syslog.LOG_USER)
|
|
|
|
import django
|
|
django.setup()
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
from ietf.utils.log import logger
|
|
|
|
try:
|
|
from ietf.utils.timezone import datetime_today
|
|
from ietf.doc.expire import ( in_draft_expire_freeze, get_expired_drafts, expirable_drafts,
|
|
send_expire_notice_for_draft, expire_draft, clean_up_draft_files )
|
|
from ietf.doc.models import Document
|
|
|
|
if not in_draft_expire_freeze():
|
|
syslog.syslog("Expiring drafts ...")
|
|
for doc in get_expired_drafts():
|
|
# verify expirability -- it might have changed after get_expired_drafts() was run
|
|
# (this whole loop took about 2 minutes on 04 Jan 2018)
|
|
# N.B., re-running expirable_drafts() repeatedly is fairly expensive. Where possible,
|
|
# it's much faster to run it once on a superset query of the objects you are going
|
|
# to test and keep its results. That's not desirable here because it would defeat
|
|
# the purpose of double-checking that a document is still expirable when it is actually
|
|
# being marked as expired.
|
|
if (expirable_drafts(Document.objects.filter(pk=doc.pk)).exists()
|
|
and doc.expires < datetime_today() + datetime.timedelta(1)):
|
|
send_expire_notice_for_draft(doc)
|
|
expire_draft(doc)
|
|
syslog.syslog(" Expired draft %s-%s" % (doc.name, doc.rev))
|
|
|
|
syslog.syslog("Cleaning up draft files")
|
|
clean_up_draft_files()
|
|
except Exception as e:
|
|
logger.error("Exception in expire-ids: %s" % e)
|