Created
July 30, 2018 12:27
-
-
Save elegantcoder/bc3132424b0eb9a04e42cb6c037f75bb to your computer and use it in GitHub Desktop.
Sidekiq.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
from redis import Redis | |
import simplejson | |
import os | |
class Sidekiq(object): | |
"""Dirt simple Sidekiq client in Python. Can be used to create jobs.""" | |
def __init__(self): | |
host = os.environ['SIDEKIQ_REDIS_HOST'] | |
port = os.environ['SIDEKIQ_REDIS_PORT'] | |
db = os.environ['SIDEKIQ_REDIS_DB'] | |
self.redis = Redis(host=host, port=int(port), db=int(db)) | |
def push(self, queue, object): | |
key = "queue:%s" % queue | |
self.redis.lpush(key, simplejson.dumps(object)) | |
def pop(self, queue): | |
key = "queue:%s" % queue | |
return simplejson.loads(self.redis.pop(key)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment