def __init__(self, proc_id, in_tube, out_tube, api_key=None): """Initializes class attributes. proc_id = unique string identification for worker in_tube = input data tube out_tube = output data tube api_key = optional api key for some scavengers """ host, port = global_settings.BEANSTALKD.split(':') super(Scavenger, self).__init__(in_tube, host, int(port)) self.api_key = api_key self.in_tube = in_tube self.out_tube = out_tube self.out_queue = connect_beanstalk(host, port, out_tube, out_tube) logging.info("Scavenger %s started!" % proc_id)
def cycle(self): job = None try: #self.log.info('waiting for jobs.') job = self.conn.reserve() if job is not None: # self.log.info('got job with id #%d' % job.jid) self.on_job(Job(job)) except SocketError: # TODO: this does not work when restarting beanstalk self.conn = connect_beanstalk(self.host, self.port, self.tube, self.tube) except Exception, e: self.log.exception('got unexpected exception when running job') if job is not None: job.bury()
def __init__(self, tube='default', host='localhost', port=11300): self.tube = tube self.host, self.port = host, port self.conn = connect_beanstalk(host, port, tube, tube)