From 1841f398847422461bb6dd4468b2e1f0d4ce1e65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vicent=20P=C3=A9rez?= Date: Sat, 9 Dec 2017 13:30:37 +0100 Subject: [PATCH] Check if worker there is identity available --- myworker.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/myworker.js b/myworker.js index 4f03e3f..bec8492 100644 --- a/myworker.js +++ b/myworker.js @@ -1,13 +1,14 @@ // Execution example -> $node myworker.js "tcp://localhost:8060" "Worker1" "Ready" "Done" -v var zmq = require("zmq"); -var resp = zmq.socket("req"); +var req = zmq.socket("req"); + +// Getting atributes from command line arguments var args = process.argv.slice(2); var backend_url = args[0] || "tcp://localhost:8060"; var my_id = args[1] || "NONE"; var disp_text = args[2] || "Ready"; var reply_text = args[3] || "Done"; - var verbose = false; if(args[args.length - 1] == "-v"){ @@ -15,31 +16,30 @@ if(args[args.length - 1] == "-v"){ args.pop(); } -resp.indentity = my_id; -resp.connect(backend_url); +if(my_id != "NONE") + req.identity = my_id; + +req.connect(backend_url); +req.send(disp_text); if(verbose){ console.log('Worker (%s) connected to "%s"', my_id, backend_url); + console.log('Worker (%s) has sent its first connection message: "%s"', my_id, disp_text); } -resp.on("message", function(client, delimiter, msg){ - if(verbose){ - console.log('Worker (%s) has received request "%s" from client (%s)', - my_id, msg.toString(), client); - } +req.on("message", function(client, delimiter, msg){ + if(verbose) + console.log('Worker (%s) has received request ["%s"] from client (%s)', my_id, msg.toString(), client); + setTimeout(function(){ - resp.send([client,'',reply_text]); - if(verbose){ + req.send([client,'',reply_text]); + if(verbose) console.log('Worker (%s) has sent its reply "%s"', my_id, reply_text); - } }, 1000); }); -resp.send(con_text); -if(verbose){ - console.log('Worker (%s) has sent its first connection message: "%s"', my_id, disp_text); -} +