aws-lambda-runner 1.2.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/js/request.js +18 -11
- data/lib/lambda_runner.rb +10 -12
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c6974bc3e8c91e3625933ccb2e4937868ce9b6db
|
4
|
+
data.tar.gz: 36f2002e3ee8d0d5aa57b3eddb70ce1e05f81158
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94fc927d30b90795b845934f1f8f49031c694b227a68f9b12032cd4812e72871e1234823a89159fd8b3b0fe7afd7be36472ebb7e8034d1df71e92d06e59827aa
|
7
|
+
data.tar.gz: 1d852324b869731f44f2192ab9d42151ce31f1766ef5e9d27ae85b3c364805c86641e3c7f77acc0cc7a01d7d43ffdf3a31d8ef8ae310de3849343b0a69fbc326
|
data/js/request.js
CHANGED
@@ -4,12 +4,13 @@ var url = require('url');
|
|
4
4
|
var next_id = 0;
|
5
5
|
var done = {};
|
6
6
|
var errors = {};
|
7
|
+
var successes = {};
|
7
8
|
var timeout = {};
|
8
9
|
|
9
10
|
exports.request = function(req, res, opts, handler) {
|
10
11
|
if (req.method === 'POST') {
|
11
12
|
var id = next_id;
|
12
|
-
var
|
13
|
+
var postOutput = '';
|
13
14
|
next_id += 1;
|
14
15
|
req.on('data', function(chunk) {
|
15
16
|
setTimeout(function() {
|
@@ -17,14 +18,16 @@ exports.request = function(req, res, opts, handler) {
|
|
17
18
|
timeout[id] = true;
|
18
19
|
}
|
19
20
|
}, opts.timeout);
|
20
|
-
|
21
|
+
postOutput += chunk.toString();
|
21
22
|
});
|
22
23
|
req.on('end', function(chunk) {
|
23
|
-
handler(JSON.parse(
|
24
|
+
handler(JSON.parse(postOutput), {
|
24
25
|
done: function(err, message) {
|
25
26
|
if (err) {
|
26
27
|
errors[id] = err;
|
27
28
|
console.warn('Error:', err);
|
29
|
+
} else {
|
30
|
+
successes[id] = message;
|
28
31
|
}
|
29
32
|
console.info('Finished:', message);
|
30
33
|
done[id] = true;
|
@@ -34,6 +37,7 @@ exports.request = function(req, res, opts, handler) {
|
|
34
37
|
res.writeHead(200, {'Content-Type': 'text/plain'});
|
35
38
|
res.end(String(id));
|
36
39
|
} else if (req.method === 'DELETE') {
|
40
|
+
// FIXME untested
|
37
41
|
res.writeHead(202, {'Content-Type': 'text/plain'});
|
38
42
|
var terminationMessage = 'Terminating server at http://[localhost]:' + opts.port + ' for ' + opts['module-path'] + ' / ' + opts.handler;
|
39
43
|
res.end(terminationMessage + '\n');
|
@@ -42,17 +46,20 @@ exports.request = function(req, res, opts, handler) {
|
|
42
46
|
} else if (req.method === 'GET') {
|
43
47
|
var request_id = parseInt(url.parse(req.url, true).query.id);
|
44
48
|
var status = 200;
|
45
|
-
var
|
46
|
-
|
47
|
-
|
49
|
+
var getOutput = null;
|
50
|
+
|
51
|
+
if (successes[request_id]) {
|
52
|
+
status = 201;
|
53
|
+
getOutput = successes[request_id];
|
48
54
|
} else if (errors[request_id]) {
|
49
55
|
status = 502;
|
50
|
-
|
51
|
-
} else if (
|
52
|
-
status =
|
56
|
+
getOutput = errors[request_id];
|
57
|
+
} else if (timeout[request_id]) {
|
58
|
+
status = 504;
|
53
59
|
}
|
54
|
-
|
55
|
-
res.
|
60
|
+
|
61
|
+
res.writeHead(status, {'Content-Type': 'application/json'});
|
62
|
+
res.end(JSON.stringify(getOutput) + '\n');
|
56
63
|
} else {
|
57
64
|
res.writeHead(500, {'Content-Type': 'text/plain'});
|
58
65
|
res.end('Not implemented: ' + req.method + '\n');
|
data/lib/lambda_runner.rb
CHANGED
@@ -50,21 +50,19 @@ module LambdaRunner
|
|
50
50
|
"http://localhost:#{@port}/"
|
51
51
|
end
|
52
52
|
|
53
|
-
def wait(response)
|
54
|
-
case response.code
|
55
|
-
when 201 then false
|
56
|
-
when 200 then true
|
57
|
-
when 504 then fail 'timeout'
|
58
|
-
when 502 then fail response
|
59
|
-
else fail "unknown response #{response.code}"
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
53
|
def send(message)
|
64
54
|
id = RestClient.post(url, message, content_type: :json).to_str
|
65
55
|
loop do
|
66
|
-
|
67
|
-
|
56
|
+
response = RestClient.get(url, params: { id: id })
|
57
|
+
data = JSON.parse('['+response.body+']').first
|
58
|
+
|
59
|
+
case response.code
|
60
|
+
when 200 then sleep(0.1)
|
61
|
+
when 201 then return data
|
62
|
+
when 502 then fail data
|
63
|
+
when 504 then fail 'timeout'
|
64
|
+
else fail "unknown response #{response.code}"
|
65
|
+
end
|
68
66
|
end
|
69
67
|
end
|
70
68
|
|