2014-08-06 11:43:40 +02:00
|
|
|
#!/usr/bin/env python2
|
|
|
|
# -*-coding:UTF-8 -*
|
|
|
|
|
|
|
|
"""
|
|
|
|
The ZMQ_Sub_Attribute Module
|
|
|
|
============================
|
|
|
|
|
2014-08-21 12:22:07 +02:00
|
|
|
This module is consuming the Redis-list created by the ZMQ_PubSub_Line_Q Module
|
2014-08-06 11:43:40 +02:00
|
|
|
|
2014-08-21 12:22:07 +02:00
|
|
|
It perform a sorting on the line's length and publish/forward them to
|
|
|
|
differents channels:
|
2014-08-06 11:43:40 +02:00
|
|
|
|
|
|
|
*Channel 1 if max length(line) < max
|
|
|
|
*Channel 2 if max length(line) > max
|
|
|
|
|
|
|
|
The collected informations about the processed pastes
|
|
|
|
(number of lines and maximum length line) are stored in Redis.
|
|
|
|
|
|
|
|
..note:: Module ZMQ_Something_Q and ZMQ_Something are closely bound, always put
|
|
|
|
the same Subscriber name in both of them.
|
|
|
|
|
|
|
|
Requirements
|
|
|
|
------------
|
|
|
|
|
|
|
|
*Need running Redis instances. (LevelDB & Redis)
|
|
|
|
*Need the ZMQ_PubSub_Line_Q Module running to be able to work properly.
|
|
|
|
|
|
|
|
"""
|
2014-08-14 17:55:18 +02:00
|
|
|
import time
|
|
|
|
from packages import Paste
|
2014-08-06 11:43:40 +02:00
|
|
|
from pubsublogger import publisher
|
|
|
|
|
2014-08-20 15:14:57 +02:00
|
|
|
import Helper
|
2014-08-06 11:43:40 +02:00
|
|
|
|
2014-08-20 15:14:57 +02:00
|
|
|
if __name__ == "__main__":
|
2014-08-22 17:35:40 +02:00
|
|
|
publisher.port = 6380
|
2014-08-20 15:14:57 +02:00
|
|
|
publisher.channel = "Script"
|
2014-08-14 17:55:18 +02:00
|
|
|
|
2014-08-20 15:14:57 +02:00
|
|
|
config_section = 'PubSub_Global'
|
|
|
|
config_channel = 'channel'
|
|
|
|
subscriber_name = 'attributes'
|
2014-08-06 11:43:40 +02:00
|
|
|
|
2014-08-20 15:14:57 +02:00
|
|
|
h = Helper.Redis_Queues(config_section, config_channel, subscriber_name)
|
2014-08-06 11:43:40 +02:00
|
|
|
|
2014-08-14 17:55:18 +02:00
|
|
|
# Subscriber
|
2014-08-20 15:14:57 +02:00
|
|
|
h.zmq_sub(config_section)
|
2014-08-06 11:43:40 +02:00
|
|
|
|
|
|
|
# FUNCTIONS #
|
|
|
|
publisher.info("""ZMQ Attribute is Running""")
|
|
|
|
|
|
|
|
while True:
|
2014-08-14 17:55:18 +02:00
|
|
|
try:
|
2014-08-20 15:14:57 +02:00
|
|
|
message = h.redis_rpop()
|
2014-08-06 11:43:40 +02:00
|
|
|
|
2014-08-14 17:55:18 +02:00
|
|
|
if message is not None:
|
|
|
|
PST = Paste.Paste(message.split(" ", -1)[-1])
|
2014-08-06 11:43:40 +02:00
|
|
|
else:
|
2014-08-20 15:14:57 +02:00
|
|
|
if h.redis_queue_shutdown():
|
2014-08-06 11:43:40 +02:00
|
|
|
print "Shutdown Flag Up: Terminating"
|
|
|
|
publisher.warning("Shutdown Flag Up: Terminating.")
|
|
|
|
break
|
|
|
|
publisher.debug("Script Attribute is idling 10s")
|
|
|
|
time.sleep(10)
|
|
|
|
continue
|
|
|
|
|
2014-08-21 14:39:17 +02:00
|
|
|
# FIXME do it directly in the class
|
|
|
|
PST.save_attribute_redis("p_encoding", PST._get_p_encoding())
|
|
|
|
PST.save_attribute_redis("p_language", PST._get_p_language())
|
|
|
|
# FIXME why not all saving everything there.
|
2014-08-21 12:22:07 +02:00
|
|
|
PST.save_all_attributes_redis()
|
2014-08-21 14:39:17 +02:00
|
|
|
# FIXME Not used.
|
|
|
|
PST.store.sadd("Pastes_Objects", PST.p_path)
|
2014-08-06 11:43:40 +02:00
|
|
|
except IOError:
|
2014-08-14 17:55:18 +02:00
|
|
|
print "CRC Checksum Failed on :", PST.p_path
|
2014-08-21 14:39:17 +02:00
|
|
|
publisher.error('Duplicate;{};{};{};CRC Checksum Failed'.format(
|
|
|
|
PST.p_source, PST.p_date, PST.p_name))
|