Skip to content

Instantly share code, notes, and snippets.

@jterstriep
Created November 28, 2015 16:14
Show Gist options
  • Select an option

  • Save jterstriep/6975932a36abccdca9b7 to your computer and use it in GitHub Desktop.

Select an option

Save jterstriep/6975932a36abccdca9b7 to your computer and use it in GitHub Desktop.
class BaseWorker(ConsumerMixin):
# The name of the queue that this worker consumes (see queues.py)
worker_queue = None
def __init__(self, connection, config):
print "Worker Init"
self.connection = connection
self.config = config
def get_consumers(self, Consumer, channel):
return [Consumer(queues=queues[self.worker_queue],
callbacks=[self.process])]
def process(self, body, message):
try:
# This is where you process the message from the Queue
except Exception, e:
print "[%s] Processing Raised Exception: %s" % (body['id'], exc)
# Acknowledge the message to the Queue
message.ack()
# Create the connection to the Queue server.
# We use a with statement here so the connection is auto-closed
with Connection(hostname=config['host'],
port=config['port'],
userid=config['user'],
password=config['pass'],
virtual_host=config['vhost']) as conn:
try:
BaseWorker(conn, config).run()
except KeyboardInterrupt:
print('Exiting')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment