Last active
December 19, 2015 01:28
-
-
Save rtt/5875621 to your computer and use it in GitHub Desktop.
simple redis publisher
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
import redis | |
import threading | |
class Worker(threading.Thread): | |
'''Generic Main Worker class''' | |
def __init__(self, r, channels): | |
# init super | |
threading.Thread.__init__(self) | |
self.redis = r | |
# subscribe to given channels | |
self.pubsub = self.redis.pubsub() | |
self.pubsub.subscribe(channels) | |
def dispatch(self, *args, **kwargs): | |
'''Method for each worker to implement its "work"''' | |
raise NotImplementedError() | |
def run(self): | |
'''Iterates published messages and dispatches them''' | |
for item in self.pubsub.listen(): | |
self.dispatch(item) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment