From: Magnus Hagander Date: Thu, 21 Feb 2013 15:57:29 +0000 (+0100) Subject: Add varnish purger trigger X-Git-Url: http://git.postgresql.org/gitweb/?a=commitdiff_plain;h=c6344ebe1c5956be287b80351f1d849d65076983;p=pggit.git Add varnish purger trigger --- diff --git a/triggers.py b/triggers.py index 97a347e..c4cf334 100644 --- a/triggers.py +++ b/triggers.py @@ -4,3 +4,42 @@ class test(object): def pushtrigger(self, reponame, username): print "Firing push trigger for repository '%s', due to push by %s" % (reponame, username) + + +import httplib + +class varnishpurger(object): + """ + Push trigger that purges repositories from varnish. The idea being that + the repositories follow a standard gitweb url structure, and we purge + all pages related to that repository. + + Requires the config variable "host" set in the section "varnishpurge". + This can be an IP address (typically 127.0.0.1) or IP address + port + (typically 127.0.0.1:81). The trigger will always post to the URL + "/varnish-purge-url", and will include the URL to purge in the form of + a regular expression in the custom header X-Purge-URL. + """ + def __init__(self, cfg): + self.host = cfg.get('varnishpurge', 'host') + + def pushtrigger(self, reponame, username): + # Make a callback to a local varnish server to purge a repository + # from it. Assumes gitweb style URLs. + for u in ['^/gitweb$', '^/gitweb/?p=%s.git' % reponame]: + if not self._internal_purge(u): + print "Varnish purge failed, website may become slightly out of date" + return + + + def _internal_purge(self, url): + try: + conn = httplib.HTTPConnection(self.host) + conn.request("GET", "/varnish-purge-url", '', {'X-Purge-URL': url}) + resp = conn.getresponse() + conn.close() + if resp.status == 200: + return True + return False + except Exception, ex: + return False