Skip to content

Commit d6c0001

Browse files
mpawlikmalawski
authored andcommitted
RESTService executor (#25)
* added initial support for GCF * cleanup old testing call * added request retry and better logging * fixed handling of retries * Rename gcf->awsLambda * awsLambda/gcf command generalized to RESTServiceCommand.
1 parent 7e75ffb commit d6c0001

File tree

4 files changed

+70
-0
lines changed

4 files changed

+70
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
var SERVICE_URL = process.env.SERVICE_URL ? process.env.SERVICE_URL : "https://localhost:2000/";
2+
3+
var STORAGE = process.env.STORAGE ? process.env.STORAGE : "aws";
4+
var BUCKET = process.env.BUCKET ? process.env.BUCKET : "bucket";
5+
var PATH = process.env.PATH ? process.env.PATH : "data"; //prefix in a bucket with no leading or trailing slashes
6+
7+
exports.service_url = SERVICE_URL;
8+
9+
exports.options = {
10+
"storage": STORAGE,
11+
"bucket": BUCKET,
12+
"prefix": PATH
13+
};
14+

functions/RESTServiceCommand.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
var request = require('requestretry');
2+
var executor_config = require('./RESTServiceCommand.config.js');
3+
var identity = function(e) {return e};
4+
5+
6+
7+
function RESTServiceCommand(ins, outs, config, cb) {
8+
9+
var options = executor_config.options;
10+
if(config.executor.hasOwnProperty('options')) {
11+
var executorOptions = config.executor.options;
12+
for (var opt in executorOptions) {
13+
if(executorOptions.hasOwnProperty(opt)) {
14+
options[opt] = executorOptions[opt];
15+
}
16+
}
17+
}
18+
var executable = config.executor.executable;
19+
var jobMessage = {
20+
"executable": executable,
21+
"args": config.executor.args,
22+
"env": (config.executor.env || {}),
23+
"inputs": ins.map(identity),
24+
"outputs": outs.map(identity),
25+
"options": options
26+
};
27+
28+
var url = executor_config.service_url;
29+
30+
console.log("Executing: " + JSON.stringify(jobMessage) + "@" + url);
31+
32+
function requestCb(err, response, body) {
33+
if (err) {
34+
console.log("Function: " + executable + " error: " + err);
35+
cb(err, outs);
36+
return
37+
}
38+
if (response) {
39+
console.log("Function: " + executable + " response status code: " + response.statusCode + " number of request attempts: " + response.attempts)
40+
}
41+
console.log("Function: " + executable + " data: " + body.toString());
42+
cb(null, outs);
43+
}
44+
45+
46+
var req = request.post(
47+
{timeout:600000, url:url, json:jobMessage, headers: {'Content-Type' : 'application/json', 'Accept': '*/*'}}, requestCb);
48+
49+
50+
}
51+
52+
53+
exports.RESTServiceCommand = RESTServiceCommand;

functions/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var fsp = require('./fileSplitter.js'),
22
cmd = require('./command.js'),
33
amqpCmd = require('./amqpCommand.js'),
4+
RESTCmd = require('./RESTServiceCommand.js'),
45
scanDir = require('./DirScanner').scanDir;
56

67
function print(ins, outs, config, cb) {
@@ -210,6 +211,7 @@ exports.length = length;
210211
exports.fileSplitter = fsp.fileSplitter;
211212
exports.command = cmd.command;
212213
exports.amqpCommand = amqpCmd.amqpCommand;
214+
exports.RESTServiceCommand = RESTCmd.RESTServiceCommand;
213215
exports.exit = exit;
214216
exports.command_print = cmd.command_print;
215217
exports.command_notifyevents = cmd.command_notifyevents;

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"form-data": "",
3737
"nodeunit": "",
3838
"request": "",
39+
"requestretry": "",
3940
"q": "",
4041
"traverse": "",
4142
"istanbul": "",

0 commit comments

Comments
 (0)