mirror of
https://github.com/ail-project/ail-framework.git
synced 2024-11-30 09:47:17 +00:00
Alexandre Dulaunoy
7bdd4a41a5
The indexer module indexes all the pastes using Whoosh. The module can be extended to support additional full-text indexers in the future.
58 lines
1.5 KiB
Python
Executable file
58 lines
1.5 KiB
Python
Executable file
#!/usr/bin/env python2
|
|
# -*-coding:UTF-8 -*
|
|
"""
|
|
The ZMQ_Sub_Indexer_Q Module
|
|
============================
|
|
|
|
The ZMQ_Sub_Indexer_Q module subscribes to PubSub_Global ZMQ channel
|
|
and bufferizes the data in a Redis FIFO.
|
|
|
|
The FIFO will be then processed by the Indexer scripts (ZMQ_Sub_Indexer)
|
|
handling the indexing process of the files seen.
|
|
|
|
"""
|
|
|
|
import redis, zmq, ConfigParser
|
|
from pubsublogger import publisher
|
|
from packages import ZMQ_PubSub
|
|
|
|
configfile = './packages/config.cfg'
|
|
|
|
def main():
|
|
"""Main Function"""
|
|
|
|
# CONFIG #
|
|
cfg = ConfigParser.ConfigParser()
|
|
cfg.read(configfile)
|
|
|
|
# REDIS #
|
|
r_serv = redis.StrictRedis(
|
|
host = cfg.get("Redis_Queues", "host"),
|
|
port = cfg.getint("Redis_Queues", "port"),
|
|
db = cfg.getint("Redis_Queues", "db"))
|
|
|
|
# LOGGING #
|
|
publisher.channel = "Queuing"
|
|
|
|
# ZMQ #
|
|
channel = cfg.get("PubSub_Global", "channel")
|
|
subscriber_name = "indexer"
|
|
|
|
Sub = ZMQ_PubSub.ZMQSub(configfile, "PubSub_Global", channel, subscriber_name)
|
|
|
|
publisher.info("""Suscribed to channel {0}""".format(channel))
|
|
|
|
# Until the service is requested to be shutdown, the service
|
|
# will get the data from the global ZMQ queue and buffer it in Redis.
|
|
|
|
while True:
|
|
Sub.get_and_lpush(r_serv)
|
|
|
|
if r_serv.sismember("SHUTDOWN_FLAGS", "Indexer_Q"):
|
|
r_serv.srem("SHUTDOWN_FLAGS", "Indexer_Q")
|
|
print "Shutdown Flag Up: Terminating"
|
|
publisher.warning("Shutdown Flag Up: Terminating.")
|
|
break
|
|
|
|
if __name__ == "__main__":
|
|
main()
|