-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
59 lines (50 loc) · 1.56 KB
/
index.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
'use strict'
const braveDebugLib = require('./brave/debug')
const braveLambdaLib = require('./brave/lambda')
const dispatch = async lambdaEvent => {
try {
if (typeof lambdaEvent === 'string') {
lambdaEvent = JSON.parse(lambdaEvent)
}
if (lambdaEvent.Records) {
// Check to see if we're receiving data from SQS
for (const args of lambdaEvent.Records) {
const processedLambdaArgs = JSON.parse(args.body)
await dispatch(processedLambdaArgs)
}
return
}
braveDebugLib.log(`Invocation: ${JSON.stringify(lambdaEvent)}`)
await braveLambdaLib.cleanEnv()
let lambdaModule
switch (lambdaEvent.action) {
case 'crawl-dispatch':
case 'crawl':
case 'record':
case 'build':
case 'assemble':
lambdaModule = require(`./brave/lambda_actions/${lambdaEvent.action}`)
break
default:
console.log('Received unexpected lambda action: ' +
lambdaEvent.action)
return
}
const [areValidArgs, msg] = await lambdaModule.validateArgs(lambdaEvent)
if (areValidArgs === false) {
braveDebugLib.log(`Invalid arguments for action: ${lambdaEvent.action}`)
braveDebugLib.log(`Received: ${JSON.stringify(lambdaEvent)}`)
braveDebugLib.log(`Error: ${msg}`)
throw msg
}
braveDebugLib.verbose(`Starting action: ${lambdaEvent.action}`)
await lambdaModule.start(msg)
braveDebugLib.verbose('Finished processing report')
} catch (error) {
console.error(error)
throw error
}
}
module.exports = {
dispatch
}