diff --git a/core/renderer.py b/core/renderer.py index 5ec2458..c6c9f9e 100755 --- a/core/renderer.py +++ b/core/renderer.py @@ -59,7 +59,7 @@ def start_video_creator(id): """ global display, ffmpeg # logger.info("Starting video creator server") - display = Display(visible=1, size=(800,600)) + display = Display(visible=0, size=(800,600)) display.start() subprocess.call( [ @@ -202,7 +202,7 @@ def keep_alive(conn_send, conn_receive): print("Renderer listening...") while True: try: - manager.receive_from_queue("translations", run) + manager.receive_from_queue("glosses", run) except KeyboardInterrupt: manager.close_connections() os._exit(0) diff --git a/core/translator.py b/core/translator.py index 00f136e..9472155 100755 --- a/core/translator.py +++ b/core/translator.py @@ -12,7 +12,6 @@ Author: Wesnydy Lima Ribeiro E-Mail: wesnydy@lavid.ufpb.br """ -import json import os import pika import PikaManager @@ -38,18 +37,9 @@ def run(ch, method, properties, body): body : string Json string containing the necessary arguments for workers. """ - body = json.loads(body) print ("Translating...") - try: - gloss = traduzir(body["text"].encode("utf8")) - if body["type"] == "gloss": - manager.send_to_queue("glosses", gloss, properties) - elif body["type"] == "video": - manager.send_to_queue("translations", gloss, properties) - else: - print("Unexpected type of request") - except KeyError: - print ("Can't find text") + gloss = traduzir(body) + manager.send_to_queue("translations", gloss, properties) print ("Ok") def keep_alive(conn_send, conn_receive): diff --git a/translate-api/bin/www b/translate-api/bin/www index 6bf4a5c..d2a51e4 100755 --- a/translate-api/bin/www +++ b/translate-api/bin/www @@ -9,7 +9,7 @@ var http = require('http') /** * Define the port and store in Express. */ -const PORT = 80 +const PORT = 80; app.set('port', PORT); /** diff --git a/translate-api/controllers/translate.js b/translate-api/controllers/translate.js index 8d76d48..8813709 100644 --- a/translate-api/controllers/translate.js +++ b/translate-api/controllers/translate.js @@ -12,33 +12,25 @@ var shortid = require('shortid') , amqp = require('../helpers/amqpManager'); exports.translate = function(req, res) { - - var body = {}; - var id = shortid.generate(); - if (!req.body.text) return console.log('Text key is missing'); - body.text = req.body.text; - body.type = 'gloss'; + var id = shortid.generate(); + var text = req.body.text; - amqp.sendToQueue(body, id,'texts', false, res); - amqp.sendToQueue(body, id,'logs', true, res); - amqp.receiveFromQueue(id, 'glosses', false, res); + amqp.sendToQueue(text, id,'texts', false, res); + amqp.sendToQueue(text, id,'logs', true, res); + amqp.receiveFromQueue(id, 'translations', false, res); }; exports.urltranslate = function(req, res) { - - var body = {}; - var id = shortid.generate(); - if (!req.body.text) return console.log('Text key missing'); - body.text = req.param('text').toString('utf8'); - body.type = 'gloss'; + var id = shortid.generate(); + var text = req.param('text').toString('utf8'); - amqp.sendToQueue(body, id, 'texts', false, res); - amqp.sendToQueue(body, id, 'logs', true, res); - amqp.receiveFromQueue(id, 'glosses', false, res); + amqp.sendToQueue(text, id, 'texts', false, res); + amqp.sendToQueue(text, id, 'logs', true, res); + amqp.receiveFromQueue(id, 'translations', false, res); }; diff --git a/translate-api/controllers/video.js b/translate-api/controllers/video.js index 8ee3a49..e42240f 100644 --- a/translate-api/controllers/video.js +++ b/translate-api/controllers/video.js @@ -12,17 +12,13 @@ var shortid = require('shortid') , amqp = require('../helpers/amqpManager'); exports.createVideo = function(req, res) { + if (!req.body.gloss) + return console.log('Gloss key missing'); - var body = {}; var id = shortid.generate(); + var gloss = req.body.gloss; - if (!req.body.text) - return console.log('Text key missing'); - - body.text = req.body.text; - body.type = 'video'; - - amqp.sendToQueue(body, id, 'texts', false, res); - amqp.sendToQueue(body, id, 'logs', true, res); + amqp.sendToQueue(gloss, id, 'glosses', false, res); + amqp.sendToQueue(gloss, id, 'logs', true, res); amqp.receiveFromQueue(id, 'videos', false, res); }; diff --git a/translate-api/helpers/amqpManager.js b/translate-api/helpers/amqpManager.js index ca2cab6..57b8a52 100644 --- a/translate-api/helpers/amqpManager.js +++ b/translate-api/helpers/amqpManager.js @@ -26,7 +26,7 @@ exports.sendToQueue = function(body, id, queue, durability, res) { throw err; } ch.assertQueue(queue, {durable : durability}); - ch.sendToQueue(queue, new Buffer(JSON.stringify(body)), {correlationId : id}); + ch.sendToQueue(queue, new Buffer(body), {correlationId : id}); try { ch.close(); } -- libgit2 0.21.2