Flush memcached on every deploy

This uses pylibmc, the same memcached client library we use from Django.  If
that becomes a problem for whatever reason, all we really need to do is send
"flush_all\n" to TCP port 11211 on localhost.

(imported from commit 0b9736bd31b0549b5dabd4b735706351635a9cf2)
This commit is contained in:
Keegan McAllister 2012-11-26 16:49:00 -05:00
parent 0f20150a81
commit 41e43cb707
1 changed files with 10 additions and 0 deletions

View File

@ -2,6 +2,8 @@
import os
import sys
import subprocess
import pylibmc
import traceback
def check_output(*popenargs, **kwargs):
if 'stdout' in kwargs:
@ -31,6 +33,14 @@ if len(sys.argv) > 1:
newrev = sys.argv[2]
refname = sys.argv[3]
try:
if not pylibmc.Client(['127.0.0.1']).flush_all():
print "%sflush_all returned False%s" % (WARNING, ENDC)
# There doesn't seem to be a method to close a pylibmc Client object.
except:
print "%sCould not flush cache:%s" % (WARNING, ENDC)
traceback.print_exc()
subprocess.check_call(["git", "fetch"], stdout=open('/dev/null', 'w'))
subprocess.check_call(["git", "reset", "--hard", refname], stdout=open('/dev/null', 'w'))
#subprocess.check_call(["python", "manage.py", "syncdb"], stdout=open('/dev/null', 'w'))