2014-08-06 09:43:40 +00:00
|
|
|
#!/usr/bin/env python2
|
|
|
|
# -*-coding:UTF-8 -*
|
|
|
|
|
2014-08-14 15:55:18 +00:00
|
|
|
import redis
|
|
|
|
import ConfigParser
|
2014-08-06 09:43:40 +00:00
|
|
|
from packages import ZMQ_PubSub
|
|
|
|
from pubsublogger import publisher
|
|
|
|
|
|
|
|
configfile = './packages/config.cfg'
|
|
|
|
|
2014-08-14 15:55:18 +00:00
|
|
|
|
2014-08-06 09:43:40 +00:00
|
|
|
def main():
|
|
|
|
"""Main Function"""
|
|
|
|
|
|
|
|
# CONFIG #
|
|
|
|
cfg = ConfigParser.ConfigParser()
|
|
|
|
cfg.read(configfile)
|
|
|
|
|
|
|
|
# REDIS #
|
|
|
|
r_serv = redis.StrictRedis(
|
2014-08-14 15:55:18 +00:00
|
|
|
host=cfg.get("Redis_Queues", "host"),
|
|
|
|
port=cfg.getint("Redis_Queues", "port"),
|
|
|
|
db=cfg.getint("Redis_Queues", "db"))
|
2014-08-06 09:43:40 +00:00
|
|
|
|
|
|
|
# LOGGING #
|
|
|
|
publisher.channel = "Queuing"
|
|
|
|
|
|
|
|
# ZMQ #
|
2014-08-14 15:55:18 +00:00
|
|
|
sub = ZMQ_PubSub.ZMQSub(configfile, "PubSub_Categ", "mails_categ", "emails")
|
2014-08-06 09:43:40 +00:00
|
|
|
|
|
|
|
# FUNCTIONS #
|
|
|
|
publisher.info("""Suscribed to channel {0}""".format("mails_categ"))
|
|
|
|
|
|
|
|
while True:
|
2014-08-14 15:55:18 +00:00
|
|
|
sub.get_and_lpush(r_serv)
|
2014-08-06 09:43:40 +00:00
|
|
|
|
|
|
|
if r_serv.sismember("SHUTDOWN_FLAGS", "Mails_Q"):
|
|
|
|
r_serv.srem("SHUTDOWN_FLAGS", "Mails_Q")
|
|
|
|
print "Shutdown Flag Up: Terminating"
|
|
|
|
publisher.warning("Shutdown Flag Up: Terminating.")
|
|
|
|
break
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|