@@ -44,6 +44,7 @@ def __init__(self, options, browsers):
4444 self .job = None
4545 self .beanstalk_job = None
4646 self .beanstalk = None
47+ self .memcache = None
4748 self .task = None
4849 self .xvfb = None
4950 self .hostname = socket .gethostname ()
@@ -240,6 +241,12 @@ def get_beanstalk_job(self):
240241 import zlib
241242 if self .beanstalk is None :
242243 self .beanstalk = greenstalk .Client ((self .options .beanstalk , 11300 ), encoding = None , watch = 'crawl' , use = 'alive' )
244+ if self .memcache is None :
245+ try :
246+ from pymemcache .client .base import Client
247+ self .memcache = Client (self .options .beanstalk , connect_timeout = 10 , timeout = 10 , no_delay = True )
248+ except Exception :
249+ logging .exception ("Error connecting to memcache" )
243250 self .beanstalk_job = self .beanstalk .reserve (30 )
244251 stats = self .beanstalk .stats_job (self .beanstalk_job )
245252 if stats and 'timeouts' in stats and stats ['timeouts' ] >= 3 :
@@ -255,6 +262,8 @@ def get_beanstalk_job(self):
255262 raw = self .beanstalk_job .body
256263 test_json = json .loads (zlib .decompress (raw ).decode ())
257264 self .job = self .wpt .process_job_json (test_json )
265+ if self .memcache is not None :
266+ self .job ['memcache' ] = self .memcache
258267 except greenstalk .TimedOutError :
259268 pass
260269 except Exception :
0 commit comments