Commit b1ca750fa383ec3e75758e7fb5e0330c012add51
1 parent
3cee1828
Exists in
release
translator worker release
Showing
1 changed file
with
4 additions
and
7 deletions
Show diff stats
core/translator.py
@@ -41,9 +41,6 @@ ch.setFormatter(formatter) | @@ -41,9 +41,6 @@ ch.setFormatter(formatter) | ||
41 | logger.addHandler(fh) | 41 | logger.addHandler(fh) |
42 | logger.addHandler(ch) | 42 | logger.addHandler(ch) |
43 | 43 | ||
44 | -#conn_send = pika.BlockingConnection(pika.ConnectionParameters(host='localhost',heartbeat_interval=0)) | ||
45 | -#conn_receive = pika.BlockingConnection(pika.ConnectionParameters(host='localhost',heartbeat_interval=0)) | ||
46 | - | ||
47 | manager = PikaManager.PikaManager("150.165.205.10", "test", "test") | 44 | manager = PikaManager.PikaManager("150.165.205.10", "test", "test") |
48 | 45 | ||
49 | def run(ch, method, properties, body): | 46 | def run(ch, method, properties, body): |
@@ -61,20 +58,20 @@ def run(ch, method, properties, body): | @@ -61,20 +58,20 @@ def run(ch, method, properties, body): | ||
61 | body : json object | 58 | body : json object |
62 | Informations received from queue. | 59 | Informations received from queue. |
63 | """ | 60 | """ |
64 | - logger.info("Processando a requisição " + properties.correlation_id.encode("utf-8")) | ||
65 | # body it's a json that contains text to be translating | 61 | # body it's a json that contains text to be translating |
66 | body = json.loads(body) | 62 | body = json.loads(body) |
67 | - print ("Translating...",) | 63 | + print ("Translating...") |
68 | # Initialize the translation of text | 64 | # Initialize the translation of text |
69 | - logger.info("Traduzindo texto") | ||
70 | try: | 65 | try: |
66 | + logger.info("Traduzindo: "+body["text"]+" id: "+properties.correlation_id.encode("utf-8")) | ||
71 | gloss = traduzir(body["text"].encode("utf-8")) | 67 | gloss = traduzir(body["text"].encode("utf-8")) |
72 | body["gloss"] = gloss | 68 | body["gloss"] = gloss |
73 | del body["text"] | 69 | del body["text"] |
74 | except KeyError: | 70 | except KeyError: |
71 | + logger.info("Não existe texto para traduzir") | ||
75 | pass | 72 | pass |
76 | # Send the body to the queue | 73 | # Send the body to the queue |
77 | - logger.info("Enviando para a fila de traduções") | 74 | + logger.info("Enviando glosa para a fila de traduções") |
78 | manager.send_to_queue("translations", body, properties) | 75 | manager.send_to_queue("translations", body, properties) |
79 | print ("Success") | 76 | print ("Success") |
80 | 77 |