-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcomponentService.js
More file actions
66 lines (56 loc) · 1.59 KB
/
componentService.js
File metadata and controls
66 lines (56 loc) · 1.59 KB
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
60
61
62
63
64
65
66
import { promisify } from 'util'
import * as grpc from 'grpc'
import uuidv4 from 'uuid/v4'
import { connectionOptions } from './options'
import { Scynet } from './protobufs'
import { agents } from './producer'
export class ComponentServiceImpl {
RegisterInput (call, callback) {
callback(null)
}
AgentStart (call, callback) {
callback(null)
}
AgentStop (call, callback) {
callback(null)
}
AgentStatus (call, callback) {
callback(null, { running: agents.includes(x => x.uuid === call.uuid) })
}
AgentList (call, callback) {
callback(null, { agents: agents })
}
}
function convertAgent (uuid, shape, componentId) {
return {
uuid: uuid,
componentType: 'scynet-market-harvester',
componentId: componentId,
inputs: [],
outputs: [{
dimension: shape
}],
frequency: 60 * 60,
_module: module
}
}
for (let key in Scynet.Hatchery.prototype) {
let value = Scynet.Hatchery.prototype[key]
if (typeof value === 'function') {
Scynet.Hatchery.prototype[key + 'Async'] = promisify(value)
}
}
const hatchery = new Scynet.Hatchery(connectionOptions.hatcheryAddress, grpc.credentials.createInsecure())
export default async (server, componentId = uuidv4()) => {
server.addService(Scynet.Component.service, new ComponentServiceImpl())
await hatchery.RegisterComponentAsync({
uuid: componentId,
address: connectionOptions.componentAddress,
runnerType: ['scynet-market-harvester']
})
await Promise.all(agents.map(agent =>
hatchery.RegisterAgentAsync({
agent: convertAgent(agent.uuid, agent.shape, componentId)
})
))
}