generated from negebauer/js-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_agents.js
43 lines (32 loc) · 875 Bytes
/
update_agents.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
/* eslint-disable camelcase */
function extractAgentInfoFromEvent(event, Agent) {
if (!event) return Agent.log('No event')
const { payload } = event
if (!payload) return Agent.log('No payload')
const { agentsInfo } = payload
if (!agentsInfo) return Agent.log('No agentsInfo')
if (agentsInfo.length === 0) return Agent.log('agentsInfo is empty')
return agentsInfo
}
function check() {
// Do nothing
//
}
function receive({ event, Agent }) {
const agentsInfo = extractAgentInfoFromEvent(event, Agent)
if (!agentsInfo) return
agentsInfo.forEach(({ agentName, agentCode }) => {
Agent.credential(agentName, agentCode)
})
}
function agentReceive() {
const event = this.incomingEvents()[0]
return receive({ Agent: this, event })
}
Agent.check = check
Agent.receive = agentReceive
module.exports = {
check,
receive,
agentReceive,
}