Commit b6a9ff7d5df6d55ebd2fab0301b0438dc30722ff

Authored by Wesnydy Ribeiro
1 parent ed8c0256
Exists in release

Documentation of Extractor.py

core/extractor.py
@@ -20,15 +20,16 @@ import pika @@ -20,15 +20,16 @@ import pika
20 import PikaManager 20 import PikaManager
21 import pysrt 21 import pysrt
22 import json 22 import json
  23 +import logging #Logging
  24 +
23 from thread import start_new_thread 25 from thread import start_new_thread
24 from time import sleep 26 from time import sleep
25 from urllib import urlretrieve 27 from urllib import urlretrieve
26 -import logging #Logging  
27 28
28 logger = logging.getLogger('extractor') 29 logger = logging.getLogger('extractor')
29 logger.setLevel(logging.DEBUG) 30 logger.setLevel(logging.DEBUG)
30 31
31 -fh = logging.FileHandler('extractor.log') 32 +fh = logging.FileHandler('../log/extractor.log')
32 fh.setLevel(logging.DEBUG) 33 fh.setLevel(logging.DEBUG)
33 34
34 ch = logging.StreamHandler() 35 ch = logging.StreamHandler()
@@ -41,12 +42,26 @@ ch.setFormatter(formatter) @@ -41,12 +42,26 @@ ch.setFormatter(formatter)
41 logger.addHandler(fh) 42 logger.addHandler(fh)
42 logger.addHandler(ch) 43 logger.addHandler(ch)
43 44
44 -manager = PikaManager.PikaManager('150.165.205.10', "test", "test") 45 +manager = PikaManager.PikaManager("150.165.205.10", "test", "test")
45 46
46 #conn_send = pika.BlockingConnection(pika.ConnectionParameters(host='localhost',heartbeat_interval=0)) 47 #conn_send = pika.BlockingConnection(pika.ConnectionParameters(host='localhost',heartbeat_interval=0))
47 #conn_receive = pika.BlockingConnection(pika.ConnectionParameters(host='localhost',heartbeat_interval=0)) 48 #conn_receive = pika.BlockingConnection(pika.ConnectionParameters(host='localhost',heartbeat_interval=0))
48 49
49 def run(ch, method, properties, body): 50 def run(ch, method, properties, body):
  51 + """
  52 + Execute the worker.
  53 +
  54 + Parameters
  55 + ----------
  56 + ch : object
  57 + Channel of communication.
  58 + method : function
  59 + Callback method.
  60 + properties : object
  61 + Message containing a set of 14 properties.
  62 + body : json object
  63 + Informations received from queue.
  64 + """
50 logger.info("Processando a requisição " + properties.correlation_id.encode("utf-8")) 65 logger.info("Processando a requisição " + properties.correlation_id.encode("utf-8"))
51 # body it's a json that contains subtitle file 66 # body it's a json that contains subtitle file
52 body = json.loads(body) 67 body = json.loads(body)
@@ -80,10 +95,23 @@ def run(ch, method, properties, body): @@ -80,10 +95,23 @@ def run(ch, method, properties, body):
80 os.remove(filename) 95 os.remove(filename)
81 # Send the body to the queue 96 # Send the body to the queue
82 logger.info("Enviando para a fila de extrações") 97 logger.info("Enviando para a fila de extrações")
83 - manager.send_to_queue("extractions",body, properties) 98 + manager.send_to_queue("extractions", body, properties)
84 print ("Sucess") 99 print ("Sucess")
85 100
86 def calculate_ms(time_in): 101 def calculate_ms(time_in):
  102 + """
  103 + Calculates timestamp in milliseconds.
  104 +
  105 + Parameters
  106 + ----------
  107 + time_in : string
  108 + Time in of timestamp.
  109 +
  110 + Returns
  111 + -------
  112 + number
  113 + The timestamp in milliseconds.
  114 + """
87 time = time_in.split(":") 115 time = time_in.split(":")
88 time = time[:2] + time[2].split(",") 116 time = time[:2] + time[2].split(",")
89 hour = int(time[0]) * 3600000 117 hour = int(time[0]) * 3600000
@@ -93,6 +121,16 @@ def calculate_ms(time_in): @@ -93,6 +121,16 @@ def calculate_ms(time_in):
93 return millisec 121 return millisec
94 122
95 def keep_alive(conn_send, conn_receive): 123 def keep_alive(conn_send, conn_receive):
  124 + """
  125 + Keep the connection alive.
  126 +
  127 + Parameters
  128 + ----------
  129 + conn_send : object
  130 + Connection of writer.
  131 + conn_receive : object
  132 + Connection of receiver.
  133 + """
96 while True: 134 while True:
97 sleep(30) 135 sleep(30)
98 try: 136 try:
@@ -103,6 +141,7 @@ def keep_alive(conn_send, conn_receive): @@ -103,6 +141,7 @@ def keep_alive(conn_send, conn_receive):
103 141
104 start_new_thread(keep_alive, (manager.get_conn_send(), manager.get_conn_receive())) 142 start_new_thread(keep_alive, (manager.get_conn_send(), manager.get_conn_receive()))
105 143
  144 +print("Extractor listening...")
106 while True: 145 while True:
107 try: 146 try:
108 manager.receive_from_queue("requests", run) 147 manager.receive_from_queue("requests", run)
@@ -31,7 +31,7 @@ PATH_VIDEO="/home/caiomcg/videos/" @@ -31,7 +31,7 @@ PATH_VIDEO="/home/caiomcg/videos/"
31 logger = logging.getLogger('mixer') 31 logger = logging.getLogger('mixer')
32 logger.setLevel(logging.DEBUG) 32 logger.setLevel(logging.DEBUG)
33 33
34 -fh = logging.FileHandler('mixer.log') 34 +fh = logging.FileHandler('../log/mixer.log')
35 fh.setLevel(logging.DEBUG) 35 fh.setLevel(logging.DEBUG)
36 36
37 ch = logging.StreamHandler() 37 ch = logging.StreamHandler()
@@ -47,7 +47,7 @@ logger.addHandler(ch) @@ -47,7 +47,7 @@ logger.addHandler(ch)
47 #conn_send = pika.BlockingConnection(pika.ConnectionParameters(host='localhost',heartbeat_interval=0)) 47 #conn_send = pika.BlockingConnection(pika.ConnectionParameters(host='localhost',heartbeat_interval=0))
48 #conn_receive = pika.BlockingConnection(pika.ConnectionParameters(host='localhost',heartbeat_interval=0)) 48 #conn_receive = pika.BlockingConnection(pika.ConnectionParameters(host='localhost',heartbeat_interval=0))
49 49
50 -manager = PikaManager.PikaManager('150.165.205.10', "test", "test") 50 +manager = PikaManager.PikaManager("150.165.205.10", "test", "test")
51 51
52 def main_video_height(main_video): 52 def main_video_height(main_video):
53 """ 53 """
@@ -146,7 +146,7 @@ def run(ch, method, properties, body): @@ -146,7 +146,7 @@ def run(ch, method, properties, body):
146 ch : object 146 ch : object
147 Channel of communication. 147 Channel of communication.
148 method : function 148 method : function
149 - Callback. 149 + Callback method.
150 properties : object 150 properties : object
151 Message containing a set of 14 properties. 151 Message containing a set of 14 properties.
152 body : json object 152 body : json object
@@ -203,6 +203,7 @@ def run(ch, method, properties, body): @@ -203,6 +203,7 @@ def run(ch, method, properties, body):
203 # Send the body to the queue 203 # Send the body to the queue
204 logger.info("Enviando para a fila de videos") 204 logger.info("Enviando para a fila de videos")
205 manager.send_to_queue("videos", body, properties) 205 manager.send_to_queue("videos", body, properties)
  206 + print ("Success")
206 207
207 # Starts listening 208 # Starts listening
208 print("Mixer listening...") 209 print("Mixer listening...")
core/translator.py
@@ -55,7 +55,7 @@ def run(ch, method, properties, body): @@ -55,7 +55,7 @@ def run(ch, method, properties, body):
55 ch : object 55 ch : object
56 Channel of communication. 56 Channel of communication.
57 method : function 57 method : function
58 - Callback. 58 + Callback method.
59 properties : object 59 properties : object
60 Message containing a set of 14 properties. 60 Message containing a set of 14 properties.
61 body : json object 61 body : json object
@@ -99,6 +99,7 @@ def keep_alive(conn_send, conn_receive): @@ -99,6 +99,7 @@ def keep_alive(conn_send, conn_receive):
99 99
100 start_new_thread(keep_alive, (manager.get_conn_send(), manager.get_conn_receive())) 100 start_new_thread(keep_alive, (manager.get_conn_send(), manager.get_conn_receive()))
101 101
  102 +print("Translator listening...")
102 while True: 103 while True:
103 try: 104 try:
104 manager.receive_from_queue("extractions", run) 105 manager.receive_from_queue("extractions", run)