Last active
February 21, 2018 16:57
-
-
Save bitrot-sh/cbe8e642136b727b0c8922277279ed60 to your computer and use it in GitHub Desktop.
This file contains 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 | |
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