Skip to content

Instantly share code, notes, and snippets.

@mattrasband
Last active January 3, 2017 00:54
Show Gist options
  • Save mattrasband/040be045e7e51150aabb4012d40012f3 to your computer and use it in GitHub Desktop.
Save mattrasband/040be045e7e51150aabb4012d40012f3 to your computer and use it in GitHub Desktop.
ticktock-worker.py
#!/usr/bin/env python3.6
import asyncio
import aioamqp
async def main(loop=None):
if loop is None:
loop = asyncio.get_event_loop()
transport, protocol = await aioamqp.connect()
channel = await protocol.channel()
work_q = (await channel.queue_declare(queue_name='job_name'))['queue']
await channel.queue_bind(work_q, 'my.scheduler', routing_key='cron.minute.1')
async def job(chan, body, envelope, properties):
print('Performing job on minute...')
await channel.basic_consume(job, queue_name=work_q)
loop = asyncio.get_event_loop()
loop.create_task(main(loop))
try:
loop.run_forever()
finally:
loop.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment