@@ -2,29 +2,32 @@ const { createClient, ZooKeeper } = require('./wrapper.js');
2
2
const notifier = require ( './notifier.js' ) ;
3
3
const logger = require ( './logger.js' ) ;
4
4
5
- const noop = ( ) => { } ;
6
-
7
5
function emit ( client , path ) {
8
6
logger . log ( `(${ path } ) client id: ${ client . client_id } ` ) ;
9
7
notifier . emit ( 'createWorker' , client ) ;
10
8
}
11
9
12
- async function createWorker ( ) {
13
- const client = createClient ( ) ;
14
- client . connect ( { } , noop ) ;
15
-
16
- client . on_connected ( ) ;
17
- notifier . emit ( 'connect' , `createWorker: session established, id=${ client . client_id } ` ) ;
18
-
10
+ async function createWorkerPath ( client , path ) {
19
11
try {
20
12
// eslint-disable-next-line no-bitwise
21
- const path = await client . create ( '/workers/worker-' , '' , ZooKeeper . ZOO_EPHEMERAL | ZooKeeper . ZOO_SEQUENCE ) ;
22
- emit ( client , path ) ;
13
+ const createdPath = await client . create ( path , '' , ZooKeeper . ZOO_EPHEMERAL | ZooKeeper . ZOO_SEQUENCE ) ;
14
+ emit ( client , createdPath ) ;
23
15
} catch ( error ) {
24
16
logger . error ( error ) ;
25
17
}
26
18
}
27
19
20
+ async function createWorker ( ) {
21
+ const client = createClient ( ) ;
22
+
23
+ client . on ( 'connect' , ( ) => {
24
+ notifier . emit ( 'connect' , `createWorker: session established, id=${ client . client_id } ` ) ;
25
+ createWorkerPath ( client , '/workers/worker-' ) ;
26
+ } ) ;
27
+
28
+ client . init ( { } ) ;
29
+ }
30
+
28
31
module . exports = {
29
32
createWorker,
30
33
} ;
0 commit comments