Skip to content

Commit a34fb15

Browse files
...
1 parent dc87950 commit a34fb15

File tree

5 files changed

+53
-10
lines changed

5 files changed

+53
-10
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,6 @@ typings/
159159
.serverless
160160

161161

162-
# End of https://www.gitignore.io/api/node,coffeescript,intellij+all
162+
# End of https://www.gitignore.io/api/node,coffeescript,intellij+all
163+
164+
clientIdentity.json

package-lock.json

Lines changed: 21 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@
2020
"clusterws-client-js": "git+https://github.com/fundon/ClusterWS-Client-JS.git",
2121
"comedy": "^1.6.0",
2222
"commander": "^2.18.0",
23+
"create-if-not-exist": "0.0.2",
2324
"express": "^4.16.3",
2425
"graphql-request": "^1.8.2",
2526
"handlebars": "^4.0.12",
2627
"handlebars-helpers": "^0.10.0",
2728
"html-entities": "^1.2.1",
2829
"request": "^2.88.0",
2930
"request-promise-native": "^1.0.5",
31+
"uuid": "^3.3.2",
3032
"uws": "^10.148.1",
3133
"winston": "^3.0.0"
3234
},

src/Setup.coffee

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@ Comedy = require 'comedy'
33
Awilix = require 'awilix'
44
Winston = require 'winston'
55
Graph = require '@dagrejs/graphlib'
6+
createIfNotExist = require 'create-if-not-exist'
7+
uuidv1 = require 'uuid/v1'
8+
fs = require('fs')
9+
10+
clientIdentity =
11+
uuid: uuidv1()
12+
createIfNotExist('./clientIdentity.json', JSON.stringify(clientIdentity))
13+
clientIdentity = JSON.parse(fs.readFileSync('./clientIdentity.json', 'utf8'))
14+
#console.log 'client identity is ' + clientIdentity.uuid
615

716
graphClass = Graph.Graph
817
graphInstance = new graphClass()
@@ -27,6 +36,7 @@ container.register
2736
actorSystem: Awilix.asValue actorSystem
2837
graphClass: Awilix.asClass graphClass
2938
graph: Awilix.asValue graphInstance
39+
clientIdentity: Awilix.asValue clientIdentity
3040

3141
opts = {}
3242

src/services/SetupClient.coffee

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,39 +9,47 @@ graphQlRequest = require 'graphql-request'
99
program = require 'commander'
1010
path = require 'path'
1111
ClusterWS = require './../../node_modules/clusterws-client-js/dist/index.js'
12-
request = require('request')
12+
request = require 'request'
13+
uuidv1 = require 'uuid/v1'
1314

1415
class SetupClient
1516

1617
constructor: (opts) ->
1718
@g = opts.graph
19+
@clientIdentity = opts.clientIdentity
20+
21+
getWorkerId: () =>
22+
@clientIdentity
1823

1924
setup: () ->
2025

2126
console.log '--help for command reference'
2227

2328
program.usage('testwork <server ip address> <server port>').command('testwork <server ip address> <server port>').action (serverIp, serverPort, cmd) =>
2429
console.log 'send test work event'
25-
await this.sendTestWorkEvent serverIp, serverPort
30+
workerId = this.getWorkerId()
31+
await this.sendTestWorkEvent workerId, serverIp, serverPort
2632

2733
# Deploy a ContractPen contract to an Accord Project folder structure
2834
program.usage('deploy <guid> <dir>').command('deploy <guid> <dir>').action (guid, directoryToCreate, cmd) =>
2935
console.log 'deploying guid ' + guid
3036
console.log 'to directory ' + directoryToCreate
3137
contractJson = await this.fetchContractJsonFromServer guid
32-
this.createProject directoryToCreate, contractJson
38+
await this.createProject directoryToCreate, contractJson
3339

3440
# Subscribe to server to await work events
3541
program.usage('subscribe <server ip address> <server port>').command('subscribe <server ip address> <server port>').action (serverIp, serverPort, cmd) =>
3642
console.log 'subscribe, attempting to subscribe to server for work'
3743
console.log 'attempting ' + serverIp + ':' + serverPort
38-
this.subscribeCluster serverIp, serverPort
44+
await this.subscribeCluster serverIp, serverPort
3945

4046
program.parse process.argv
4147

4248
# Submit test task to the server
43-
sendTestWorkEvent: (serverId, port) ->
49+
sendTestWorkEvent: (workerId, serverId, port) ->
4450
workData =
51+
uuid: uuidv1()
52+
workerId: workerId
4553
command: 'deploy'
4654
params: ['b03d0879-1545-4ce9-bd08-7915457ce92c', 'testcicerofolder']
4755

@@ -67,6 +75,9 @@ class SetupClient
6775

6876
# Client must execute the job as given from the server and reply the result back to the server
6977
socket.on 'executeJob', (job) ->
78+
if (job.command == 'deploy')
79+
await this.createProject job.params[0], job.params[1]
80+
socket.send 'finishedJob', 'jobid'
7081
console.log 'client executing job'
7182

7283
# When the server is connected we send back to the server that we are ready to accept commands
@@ -89,7 +100,7 @@ class SetupClient
89100
socket.on 'disconnect', (code, reason) ->
90101
# your code to execute on disconnect event
91102
return
92-
103+
return
93104

94105
doNothing: (error) -> 0
95106

0 commit comments

Comments
 (0)