Skip to content

Instantly share code, notes, and snippets.

@renanpalmeira
Last active March 3, 2016 20:37
Show Gist options
  • Save renanpalmeira/47aec8bef62b5b38a2ef to your computer and use it in GitHub Desktop.
Save renanpalmeira/47aec8bef62b5b38a2ef to your computer and use it in GitHub Desktop.
import redis
import sys
import logging
from apscheduler.schedulers.blocking import BlockingScheduler
LOG_FILENAME = 'clock.log'
logging.basicConfig(level=logging.WARNING)
sched = BlockingScheduler()
redis = redis.StrictRedis(host='localhost', port=6379, db=0)
p = redis.pubsub()
p.subscribe('support')
@sched.scheduled_job('interval', seconds=5)
def pubsub():
logging.warning('Listen pub/sub...')
message = p.get_message()
if message:
logging.warning('Subscriber %s', message['data'])
redis.rpush('marks', message['data'])
try:
sched.start()
except Exception, e:
sched.shutdown(wait=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment