aws-lambda-runner 1.3.1 → 1.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/js/request.js +78 -38
- data/lib/lambda_runner.rb +1 -0
- 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: f00a420d05400ba0db54fe75fa8ec2feff66c821
|
4
|
+
data.tar.gz: 62fbcc48883724ea62d69687321cff22bd8b22f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b89d4d941ccbf45904fae5a7cd5d06ee9bebf42ec975f4ae61fd887efe5eddb7995ac4cc3f53a1304f76aba2cea48770e6f08d929d10a1ec846aed21ad42923
|
7
|
+
data.tar.gz: b80855bc773be900831f97c0fae15c6b3055c4b901850e88fccfce46cec7d6dff13bba4701c5943b86607095d93c5d9056a424d28e5db48877b7e6dd6246a5a3
|
data/js/request.js
CHANGED
@@ -1,67 +1,107 @@
|
|
1
|
-
|
2
1
|
var url = require('url');
|
3
2
|
|
4
3
|
var next_id = 0;
|
5
|
-
|
6
|
-
var
|
7
|
-
var successes = {};
|
8
|
-
var timeout = {};
|
4
|
+
// results[id] = { threw: error, completed: [ errorValue, successValue ], timedOut: bool };
|
5
|
+
var results = {};
|
9
6
|
|
10
7
|
exports.request = function(req, res, opts, handler) {
|
8
|
+
|
11
9
|
if (req.method === 'POST') {
|
12
|
-
|
13
|
-
var
|
14
|
-
|
10
|
+
|
11
|
+
var id = ++next_id;
|
12
|
+
results[id] = {};
|
13
|
+
|
14
|
+
var requestBody = '';
|
15
|
+
|
15
16
|
req.on('data', function(chunk) {
|
17
|
+
requestBody += chunk.toString();
|
18
|
+
});
|
19
|
+
|
20
|
+
req.on('end', function(chunk) {
|
16
21
|
setTimeout(function() {
|
17
|
-
if (!
|
18
|
-
|
22
|
+
if (!results[id].completed) {
|
23
|
+
results[id].timedOut = true;
|
19
24
|
}
|
20
25
|
}, opts.timeout);
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
26
|
+
|
27
|
+
var requestObject;
|
28
|
+
try {
|
29
|
+
requestObject = JSON.parse(requestBody);
|
30
|
+
} catch (e) {
|
31
|
+
console.log("POSTed bad json: " + e.toString());
|
32
|
+
res.writeHead(400, {'Content-Type': 'text/plain'});
|
33
|
+
res.end(e.toString());
|
34
|
+
return;
|
35
|
+
}
|
36
|
+
|
37
|
+
res.writeHead(200, {'Content-Type': 'text/plain'});
|
38
|
+
res.end(String(id));
|
39
|
+
|
40
|
+
try {
|
41
|
+
handler(requestObject, {
|
42
|
+
done: function(err, message) {
|
43
|
+
results[id].completed = [ err, message ];
|
44
|
+
if (err) {
|
45
|
+
console.warn('Error:', err);
|
46
|
+
}
|
47
|
+
console.info('Finished:', message);
|
31
48
|
}
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
49
|
+
});
|
50
|
+
} catch (e) {
|
51
|
+
console.log("Handler crashed", e);
|
52
|
+
results[id].threw = e;
|
53
|
+
}
|
54
|
+
|
36
55
|
});
|
37
|
-
|
38
|
-
res.end(String(id));
|
56
|
+
|
39
57
|
} else if (req.method === 'DELETE') {
|
58
|
+
|
40
59
|
// FIXME untested
|
41
60
|
res.writeHead(202, {'Content-Type': 'text/plain'});
|
42
61
|
var terminationMessage = 'Terminating server at http://[localhost]:' + opts.port + ' for ' + opts['module-path'] + ' / ' + opts.handler;
|
43
62
|
res.end(terminationMessage + '\n');
|
44
63
|
console.info(terminationMessage);
|
45
64
|
server.close();
|
65
|
+
|
46
66
|
} else if (req.method === 'GET') {
|
67
|
+
|
47
68
|
var request_id = parseInt(url.parse(req.url, true).query.id);
|
48
|
-
var
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
69
|
+
var result = results[request_id];
|
70
|
+
|
71
|
+
var status = null;
|
72
|
+
var responseBody = null;
|
73
|
+
|
74
|
+
if (result === undefined) {
|
75
|
+
status = 404;
|
76
|
+
} else {
|
77
|
+
if (result.completed) {
|
78
|
+
if (result.completed[0] !== null) {
|
79
|
+
status = 502;
|
80
|
+
responseBody = result.completed[0];
|
81
|
+
} else {
|
82
|
+
status = 201;
|
83
|
+
responseBody = result.completed[1];
|
84
|
+
}
|
85
|
+
} else if (result.threw) {
|
86
|
+
status = 500;
|
87
|
+
responseBody = result.threw.toString();
|
88
|
+
} else if (result.timedOut) {
|
89
|
+
status = 504;
|
90
|
+
} else {
|
91
|
+
// still in progress
|
92
|
+
status = 200;
|
93
|
+
}
|
59
94
|
}
|
60
95
|
|
61
96
|
res.writeHead(status, {'Content-Type': 'application/json'});
|
62
|
-
res.end(JSON.stringify(
|
97
|
+
res.end(JSON.stringify(responseBody) + '\n');
|
98
|
+
console.log(request_id, status, result);
|
99
|
+
|
63
100
|
} else {
|
101
|
+
|
64
102
|
res.writeHead(500, {'Content-Type': 'text/plain'});
|
65
103
|
res.end('Not implemented: ' + req.method + '\n');
|
104
|
+
|
66
105
|
}
|
106
|
+
|
67
107
|
};
|
data/lib/lambda_runner.rb
CHANGED