@@ -9,39 +9,47 @@ graphQlRequest = require 'graphql-request'
9
9
program = require ' commander'
10
10
path = require ' path'
11
11
ClusterWS = require ' ./../../node_modules/clusterws-client-js/dist/index.js'
12
- request = require (' request' )
12
+ request = require ' request'
13
+ uuidv1 = require ' uuid/v1'
13
14
14
15
class SetupClient
15
16
16
17
constructor : (opts ) ->
17
18
@g = opts .graph
19
+ @clientIdentity = opts .clientIdentity
20
+
21
+ getWorkerId : () =>
22
+ @clientIdentity
18
23
19
24
setup : () ->
20
25
21
26
console .log ' --help for command reference'
22
27
23
28
program .usage (' testwork <server ip address> <server port>' ).command (' testwork <server ip address> <server port>' ).action (serverIp, serverPort, cmd) =>
24
29
console .log ' send test work event'
25
- await this .sendTestWorkEvent serverIp, serverPort
30
+ workerId = this .getWorkerId ()
31
+ await this .sendTestWorkEvent workerId, serverIp, serverPort
26
32
27
33
# Deploy a ContractPen contract to an Accord Project folder structure
28
34
program .usage (' deploy <guid> <dir>' ).command (' deploy <guid> <dir>' ).action (guid, directoryToCreate, cmd) =>
29
35
console .log ' deploying guid ' + guid
30
36
console .log ' to directory ' + directoryToCreate
31
37
contractJson = await this .fetchContractJsonFromServer guid
32
- this .createProject directoryToCreate, contractJson
38
+ await this .createProject directoryToCreate, contractJson
33
39
34
40
# Subscribe to server to await work events
35
41
program .usage (' subscribe <server ip address> <server port>' ).command (' subscribe <server ip address> <server port>' ).action (serverIp, serverPort, cmd) =>
36
42
console .log ' subscribe, attempting to subscribe to server for work'
37
43
console .log ' attempting ' + serverIp + ' :' + serverPort
38
- this .subscribeCluster serverIp, serverPort
44
+ await this .subscribeCluster serverIp, serverPort
39
45
40
46
program .parse process .argv
41
47
42
48
# Submit test task to the server
43
- sendTestWorkEvent : (serverId , port ) ->
49
+ sendTestWorkEvent : (workerId , serverId , port ) ->
44
50
workData =
51
+ uuid : uuidv1 ()
52
+ workerId : workerId
45
53
command : ' deploy'
46
54
params : [' b03d0879-1545-4ce9-bd08-7915457ce92c' , ' testcicerofolder' ]
47
55
@@ -67,6 +75,9 @@ class SetupClient
67
75
68
76
# Client must execute the job as given from the server and reply the result back to the server
69
77
socket .on ' executeJob' , (job ) ->
78
+ if (job .command == ' deploy' )
79
+ await this .createProject job .params [0 ], job .params [1 ]
80
+ socket .send ' finishedJob' , ' jobid'
70
81
console .log ' client executing job'
71
82
72
83
# When the server is connected we send back to the server that we are ready to accept commands
@@ -89,7 +100,7 @@ class SetupClient
89
100
socket .on ' disconnect' , (code , reason ) ->
90
101
# your code to execute on disconnect event
91
102
return
92
-
103
+ return
93
104
94
105
doNothing : (error ) -> 0
95
106
0 commit comments