Add script to purge emails from varnish
authorMagnus Hagander <magnus@hagander.net>
Mon, 15 Aug 2016 10:17:56 +0000 (12:17 +0200)
committerMagnus Hagander <magnus@hagander.net>
Mon, 15 Aug 2016 10:17:56 +0000 (12:17 +0200)
This is typically needed when manually editing a message such as setting
the hidden reason.

We should perhaps extend this at some point to support doing the hiding
itself, but for now that is still done manually and you just pass the
messageid to this script to clear it from the varnish caches.

loader/purge_frontend_message.py [new file with mode: 0755]

diff --git a/loader/purge_frontend_message.py b/loader/purge_frontend_message.py
new file mode 100755 (executable)
index 0000000..edab70c
--- /dev/null
@@ -0,0 +1,49 @@
+#!/usr/bin/env python
+#
+# purge_frontend_message.py - issue varnish purge for the message
+# in question, to for example force an expire of a hidden message.
+#
+
+import os
+import sys
+
+from optparse import OptionParser
+from ConfigParser import ConfigParser
+
+import psycopg2
+
+from lib.varnish import VarnishPurger
+
+if __name__ == "__main__":
+       optparser = OptionParser()
+       optparser.add_option('-m', '--msgid', dest='msgid', help='Messageid to load')
+
+       (opt, args) = optparser.parse_args()
+
+       if (len(args)):
+               print "No bare arguments accepted"
+               optparser.print_help()
+               sys.exit(1)
+
+       if not opt.msgid:
+               print "Message-id must be specified"
+               optparser.print_help()
+               sys.exit(1)
+
+       cfg = ConfigParser()
+       cfg.read('%s/archives.ini' % os.path.realpath(os.path.dirname(sys.argv[0])))
+       try:
+               connstr = cfg.get('db','connstr')
+       except:
+               connstr = 'need_connstr'
+
+       conn = psycopg2.connect(connstr)
+       curs = conn.cursor()
+
+       curs.execute("SELECT id, threadid FROM messages WHERE messageid=%(msgid)s", {
+               'msgid': opt.msgid,
+       })
+       id, threadid = curs.fetchone()
+
+       VarnishPurger(cfg).purge([int(threadid), ])
+       conn.close()