forked from yfinkelstein/node-zookeeper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateworker.js
29 lines (25 loc) · 865 Bytes
/
createworker.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
const { constants, isClientConnected } = require('./wrapper.js');
const notifier = require('./notifier.js');
const logger = require('./logger.js');
function emit(client, path) {
logger.log(`(${path}) client id: ${client.client_id}`);
notifier.emit('createWorker');
}
async function createWorkerPath(client, path) {
try {
if (!isClientConnected()) {
throw new Error('createWorkerPath: client is not connected');
}
// eslint-disable-next-line no-bitwise
const createdPath = await client.create(path, '', constants.ZOO_EPHEMERAL | constants.ZOO_SEQUENCE);
emit(client, createdPath);
} catch (error) {
logger.error('createWorkerPath', error.message);
}
}
async function createWorker(client) {
createWorkerPath(client, '/workers/worker-');
}
module.exports = {
createWorker,
};