forked from adamlaska/datatracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexpire-ids
More file actions
executable file
·53 lines (42 loc) · 2.12 KB
/
expire-ids
File metadata and controls
executable file
·53 lines (42 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/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"
virtualenv_activation = os.path.join(basedir, "env", "bin", "activate_this.py")
if os.path.exists(virtualenv_activation):
execfile(virtualenv_activation, dict(__file__=virtualenv_activation))
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.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.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)