Skip to content

Instantly share code, notes, and snippets.

@bitrot-sh
Last active February 21, 2018 16:57
Show Gist options
  • Save bitrot-sh/cbe8e642136b727b0c8922277279ed60 to your computer and use it in GitHub Desktop.
Save bitrot-sh/cbe8e642136b727b0c8922277279ed60 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
from redis import Redis
from rq import Queue
from rq_scheduler import Scheduler
from datetime import timedelta
import pynma
queue = Queue('pynma_queue', connection=Redis())
scheduler = Scheduler(connection=Redis(), queue=queue)
def requeue(mins, info):
print("Retrying in %d minutes" % mins)
scheduler.enqueue_in(timedelta(minutes=mins+1), send_event, info)
def send_event(info):
p = pynma.PyNMA(info['key'])
resp = p.push(info['app'], info['event'], info['desc'], url=info['url'], priority=info['priority'])
if resp[info['key']]['code'] == '402':
requeue(int(resp[info['key']]['resettimer']), info)
print(resp[info['key']]['code'])
return resp[info['key']]['code']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment