stub for the daemon that notices when payments happen

This commit is contained in:
Seth Schoen
2012-11-09 11:55:42 -08:00
parent a768cd6c3d
commit 4f7e9ee3b9
+37
View File
@@ -0,0 +1,37 @@
#!/usr/bin/env python
# Wait for news about payments received for sesssions and
# then mark the sessions to show that that payment was received.
# This daemon uses a different scheduling model from the
# testchallenge daemon so ONLY ONE COPY OF THIS DAEMON SHOULD
# BE RUN AT ONCE. Since this daemon takes a minimal, discrete
# action in response to a pubsub message, there should never be
# a significant backlog associated with this daemon.
import redis, signal, sys
r = redis.Redis()
ps = r.pubsub()
debug = "debug" in sys.argv
clean_shutdown = False
from daemon_common import signal_handler
signal.signal(signal.SIGTERM, signal_handler)
signal.signal(signal.SIGINT, signal_handler)
ps.subscribe(["payments", "exit"])
for message in ps.listen():
if message["type"] != "message":
continue
if message["channel"] == "payments":
if debug: print message["data"]
# TODO: Actually process the payment here :-)
continue
if message["channel"] == "exit":
break
if clean_shutdown:
print "daemon exiting cleanly"
break