2014-08-06 11:43:40 +02:00
|
|
|
#!/usr/bin/env python2
|
|
|
|
# -*-coding:UTF-8 -*
|
|
|
|
"""
|
|
|
|
The ZMQ_Pub_Global Module
|
|
|
|
=========================
|
|
|
|
|
|
|
|
This module is consuming the Redis-list created by the script ./Dir.py.
|
|
|
|
This module is as the same level of the ZMQ tree than the Module ZMQ_Feed
|
|
|
|
|
|
|
|
Whereas the ZMQ_Feed is poping the list created in redis by ZMQ_Feed_Q which is
|
2014-08-14 14:11:07 +02:00
|
|
|
listening a stream, ZMQ_Pub_Global is poping the list created in redis by
|
|
|
|
./Dir.py.
|
2014-08-06 11:43:40 +02:00
|
|
|
|
|
|
|
Thanks to this Module there is now two way to Feed the ZMQ tree:
|
|
|
|
*By a continuous stream ..seealso:: ZMQ_Feed Module
|
|
|
|
*Manually with this module and ./Dir.py script.
|
|
|
|
|
|
|
|
Requirements
|
|
|
|
------------
|
|
|
|
|
|
|
|
*Need running Redis instances. (Redis)
|
|
|
|
|
|
|
|
"""
|
2014-08-14 14:11:07 +02:00
|
|
|
import redis
|
|
|
|
import ConfigParser
|
|
|
|
import time
|
2014-08-06 11:43:40 +02:00
|
|
|
from packages import ZMQ_PubSub
|
|
|
|
from pubsublogger import publisher
|
|
|
|
|
|
|
|
configfile = './packages/config.cfg'
|
|
|
|
|
2014-08-14 14:11:07 +02:00
|
|
|
|
2014-08-06 11:43:40 +02:00
|
|
|
def main():
|
|
|
|
"""Main Function"""
|
|
|
|
|
|
|
|
# CONFIG #
|
|
|
|
cfg = ConfigParser.ConfigParser()
|
|
|
|
cfg.read('./packages/config.cfg')
|
|
|
|
|
|
|
|
# REDIS #
|
|
|
|
r_serv = redis.StrictRedis(
|
2014-08-14 14:11:07 +02:00
|
|
|
host=cfg.get("Redis_Queues", "host"),
|
|
|
|
port=cfg.getint("Redis_Queues", "port"),
|
|
|
|
db=cfg.getint("Redis_Queues", "db"))
|
2014-08-06 11:43:40 +02:00
|
|
|
|
|
|
|
# LOGGING #
|
|
|
|
publisher.channel = "Global"
|
|
|
|
|
|
|
|
# ZMQ #
|
2014-08-14 14:11:07 +02:00
|
|
|
pub_glob = ZMQ_PubSub.ZMQPub(configfile, "PubSub_Global", "global")
|
2014-08-06 11:43:40 +02:00
|
|
|
|
|
|
|
# FONCTIONS #
|
|
|
|
publisher.info("Starting to publish.")
|
|
|
|
|
|
|
|
while True:
|
|
|
|
filename = r_serv.lpop("filelist")
|
|
|
|
|
2014-08-14 14:11:07 +02:00
|
|
|
if filename is not None:
|
2014-08-06 11:43:40 +02:00
|
|
|
|
|
|
|
msg = cfg.get("PubSub_Global", "channel")+" "+filename
|
2014-08-14 14:11:07 +02:00
|
|
|
pub_glob.send_message(msg)
|
2014-08-06 11:43:40 +02:00
|
|
|
publisher.debug("{0} Published".format(msg))
|
|
|
|
else:
|
|
|
|
time.sleep(10)
|
|
|
|
publisher.debug("Nothing to publish")
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|