return function allocator() { const pendingQueueSize = pendingExecutionQueue.size(); if (!allocatingExecution && pendingQueueSize > 0 && readyForAllocation()) { allocatingExecution = true; const execution = pendingExecutionQueue.dequeue(); logger.info(`Scheduling execution: ${execution.ex_id}`); setExecutionStatus(execution.ex_id, 'scheduling') .then(() => allocateSlicer(execution) .then(() => setExecutionStatus(execution.ex_id, 'initializing', { slicer_port: execution.slicer_port, slicer_hostname: execution.slicer_hostname })) .then(() => allocateWorkers(execution, execution.workers) .catch((err) => { logger.error(`Failured to allocateWorkers ${execution.ex_id}, error: ${parseError(err)}`); return Promise.reject(err); }))) .catch((err) => { logger.error(`Failured to provision execution ${execution.ex_id}, error: ${parseError(err)}`); const errMetaData = executionMetaData(null, parseError(err)); return setExecutionStatus(execution.ex_id, 'failed', errMetaData); }) .finally(() => { allocatingExecution = false; allocator(); }); } };
function listen({ server, query } = {}) { messsagingOnline = true; if (config.clients.networkClient) { // node_master, worker io = require('socket.io-client')(hostURL, { forceNew: true, path: '/native-clustering', // transports: ['websocket'], query, }); _registerFns(io); if (self === 'node_master') { io.on('networkMessage', (networkMsg) => { const { message } = networkMsg; const func = functionMapping[message]; if (func) { func(networkMsg); } else { // if no function is registered, it is meant to by passed along to child _sendToProcesses(networkMsg); } }); } logger.debug('client network connection is online'); } else if (server) { // cluster_master io = require('socket.io')(server, { path: '/native-clustering', serveClient: false, }); _attachRoomsSocketIO(); io.on('connection', (socket) => { logger.debug('a connection to cluster_master has been made'); _registerFns(socket); }); } // TODO: message queuing will be used until formal process lifecycles are implemented while (messagingQueue.size() > 0) { const cachedMessages = messagingQueue.dequeue(); // they are put in as a tuple, [realMsg, ipcMessage] processContext.emit(cachedMessages[0], cachedMessages[1]); } }
getSlices(limit = 1) { if (this.queue.size() === 0) return []; if (limit < 1) return []; const slices = []; for (let i = 0; i < limit; i += 1) { const slice = this.queue.dequeue(); if (slice == null) break; slices.push(slice); } if (slices.length > 0) { this.events.emit('slicers:queued', this.queueLength); } return slices; }