Last active
January 3, 2017 00:54
-
-
Save mattrasband/040be045e7e51150aabb4012d40012f3 to your computer and use it in GitHub Desktop.
ticktock-worker.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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