-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.js
40 lines (32 loc) · 1 KB
/
helper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
'use strict';
const debug = require('debug')('hello-helper');
const AWS = require('mock-aws-s3');
AWS.config.basePath = __dirname + '/buckets';
const s3 = AWS.S3({ params: { Bucket: 'example' } });
function surprise(name) {
if (Math.floor(Math.random() * 100) + 1 <= 50) {
return new Error(`w00t!!! ${name} error`);
}
}
// simulates sending sms
exports.sendSms = function(data, callback) {
setTimeout(() => {
debug(`sending out sms: ${JSON.stringify(data)}`);
callback(surprise('sending-sms'), {
status: 200,
message: 'OK',
});
}, 200);
};
// simulates logging to s3
exports.logToS3 = function(data, callback) {
setTimeout(() => {
debug(`putting data to S3: ${JSON.stringify(data)}`);
s3.putObject({
Key: `row/line-${new Date().valueOf()}.json`,
Body: JSON.stringify(data),
}, (err) => {
callback(err ? err : surprise('log-to-s3'), { data, logged: true });
});
});
};