From b6a9ff7d5df6d55ebd2fab0301b0438dc30722ff Mon Sep 17 00:00:00 2001 From: Wesnydy Ribeiro Date: Tue, 13 Dec 2016 15:33:16 -0300 Subject: [PATCH] Documentation of Extractor.py --- core/extractor.py | 47 +++++++++++++++++++++++++++++++++++++++++++---- core/mixer.py | 7 ++++--- core/translator.py | 3 ++- 3 files changed, 49 insertions(+), 8 deletions(-) diff --git a/core/extractor.py b/core/extractor.py index 7b2d458..a53f9fe 100755 --- a/core/extractor.py +++ b/core/extractor.py @@ -20,15 +20,16 @@ import pika import PikaManager import pysrt import json +import logging #Logging + from thread import start_new_thread from time import sleep from urllib import urlretrieve -import logging #Logging logger = logging.getLogger('extractor') logger.setLevel(logging.DEBUG) -fh = logging.FileHandler('extractor.log') +fh = logging.FileHandler('../log/extractor.log') fh.setLevel(logging.DEBUG) ch = logging.StreamHandler() @@ -41,12 +42,26 @@ ch.setFormatter(formatter) logger.addHandler(fh) logger.addHandler(ch) -manager = PikaManager.PikaManager('150.165.205.10', "test", "test") +manager = PikaManager.PikaManager("150.165.205.10", "test", "test") #conn_send = pika.BlockingConnection(pika.ConnectionParameters(host='localhost',heartbeat_interval=0)) #conn_receive = pika.BlockingConnection(pika.ConnectionParameters(host='localhost',heartbeat_interval=0)) def run(ch, method, properties, body): + """ + Execute the worker. + + Parameters + ---------- + ch : object + Channel of communication. + method : function + Callback method. + properties : object + Message containing a set of 14 properties. + body : json object + Informations received from queue. + """ logger.info("Processando a requisição " + properties.correlation_id.encode("utf-8")) # body it's a json that contains subtitle file body = json.loads(body) @@ -80,10 +95,23 @@ def run(ch, method, properties, body): os.remove(filename) # Send the body to the queue logger.info("Enviando para a fila de extrações") - manager.send_to_queue("extractions",body, properties) + manager.send_to_queue("extractions", body, properties) print ("Sucess") def calculate_ms(time_in): + """ + Calculates timestamp in milliseconds. + + Parameters + ---------- + time_in : string + Time in of timestamp. + + Returns + ------- + number + The timestamp in milliseconds. + """ time = time_in.split(":") time = time[:2] + time[2].split(",") hour = int(time[0]) * 3600000 @@ -93,6 +121,16 @@ def calculate_ms(time_in): return millisec def keep_alive(conn_send, conn_receive): + """ + Keep the connection alive. + + Parameters + ---------- + conn_send : object + Connection of writer. + conn_receive : object + Connection of receiver. + """ while True: sleep(30) try: @@ -103,6 +141,7 @@ def keep_alive(conn_send, conn_receive): start_new_thread(keep_alive, (manager.get_conn_send(), manager.get_conn_receive())) +print("Extractor listening...") while True: try: manager.receive_from_queue("requests", run) diff --git a/core/mixer.py b/core/mixer.py index 38f8da0..5592270 100755 --- a/core/mixer.py +++ b/core/mixer.py @@ -31,7 +31,7 @@ PATH_VIDEO="/home/caiomcg/videos/" logger = logging.getLogger('mixer') logger.setLevel(logging.DEBUG) -fh = logging.FileHandler('mixer.log') +fh = logging.FileHandler('../log/mixer.log') fh.setLevel(logging.DEBUG) ch = logging.StreamHandler() @@ -47,7 +47,7 @@ logger.addHandler(ch) #conn_send = pika.BlockingConnection(pika.ConnectionParameters(host='localhost',heartbeat_interval=0)) #conn_receive = pika.BlockingConnection(pika.ConnectionParameters(host='localhost',heartbeat_interval=0)) -manager = PikaManager.PikaManager('150.165.205.10', "test", "test") +manager = PikaManager.PikaManager("150.165.205.10", "test", "test") def main_video_height(main_video): """ @@ -146,7 +146,7 @@ def run(ch, method, properties, body): ch : object Channel of communication. method : function - Callback. + Callback method. properties : object Message containing a set of 14 properties. body : json object @@ -203,6 +203,7 @@ def run(ch, method, properties, body): # Send the body to the queue logger.info("Enviando para a fila de videos") manager.send_to_queue("videos", body, properties) + print ("Success") # Starts listening print("Mixer listening...") diff --git a/core/translator.py b/core/translator.py index a65a6c6..a79d644 100755 --- a/core/translator.py +++ b/core/translator.py @@ -55,7 +55,7 @@ def run(ch, method, properties, body): ch : object Channel of communication. method : function - Callback. + Callback method. properties : object Message containing a set of 14 properties. body : json object @@ -99,6 +99,7 @@ def keep_alive(conn_send, conn_receive): start_new_thread(keep_alive, (manager.get_conn_send(), manager.get_conn_receive())) +print("Translator listening...") while True: try: manager.receive_from_queue("extractions", run) -- libgit2 0.21.2