How to use getWorkerId method in root

Best JavaScript code snippet using root

system.js

Source:system.js Github

copy

Full Screen

...109 var self = this;110 cluster.on('disconnect', function(worker) {111 self.onWorkerDisconntect(worker)112 });113 pb.log.info('System[%s]: %d workers spawned. Listening for disconnects.', this.getWorkerId(), workerCnt);114 };115 /**116 * 117 * @method 118 */119 this.onWorkerDisconntect = function(worker) {120 pb.log.debug('System[%s]: Worker [%d] disconnected', this.getWorkerId(), worker.id);121 var okToFork = true;122 var currTime = new Date().getTime();123 DISCONNECTS_CNT++;124 DISCONNECTS.push(currTime);125 //splice it down if needed. Remove first element (FIFO)126 if (DISCONNECTS.length > pb.config.fatal_error_count) {127 DISCONNECTS.splice(0, 1);128 }129 //check for unacceptable failures in specified time frame130 if (DISCONNECTS.length >= pb.config.fatal_error_count) {131 var range = DISCONNECTS[DISCONNECTS.length - 1] - DISCONNECTS[DISCONNECTS.length - config.fatal_error_count];132 if (range <= config.cluster.fatal_error_timeout) {133 okToFork = false;134 }135 else {136 pb.log.silly("System[%s]: Still within acceptable fault tolerance. TOTAL_DISCONNECTS=[%d] RANGE=[%d]", this.getWorkerId(), disconnectCnt, pb.config.fatal_error_count, range);137 }138 }139 if (okToFork && !this.isShuttingDown()) {140 var worker = cluster.fork();141 pb.log.silly("System[%s] Forked worker [%d]", this.getWorkerId(), worker ? worker.id : 'FAILED');142 }143 else if (!this.isShuttingDown()){144 pb.log.error("System[%s]: %d failures have occurred within %sms. Bailing out.", this.getWorkerId(), pb.config.fatal_error_count, pb.config.fatal_error_timeout);145 process.kill();146 }147 };148 /**149 * 150 * @method 151 */152 this.isShuttingDown = function() {153 return IS_SHUTTING_DOWN;154 };155 /**156 * 157 * @method 158 */159 this.getWorkerId = function() {160 return cluster.worker ? cluster.worker.id : 'M';161 };162 /**163 * 164 * @method 165 */166 this.registerShutdownHook = function(name, shutdownHook) {167 if (typeof name !== 'string') {168 throw new Error('A name must be provided for every shutdown hook');169 }170 SHUTDOWN_HOOKS[name] = shutdownHook;171 SHUTDOWN_PRIORITY.push(name);172 };173 /**174 * Calls shutdown on all registered system services and kills the process175 * @method shutdown176 * @param {Boolean} [killProcess=true]177 */178 this.shutdown = function(killProcess, cb) {179 if (util.isFunction(killProcess)) {180 cb = killProcess;181 killProcess = true;182 }183 if (!util.isFunction(cb)) {184 cb = util.cb;185 }186 187 //notify of shutdown188 var self = this;189 pb.log.debug('System[%s]: Shutting down...', this.getWorkerId());190 //create tasks to shutdown registered services in parallel191 var toh = null;192 var tasks = util.getTasks(SHUTDOWN_PRIORITY, function(keys, i) {193 return function(callback) {194 var timeoutHandle = setTimeout(function() {195 timeoutHandle = null;196 //TODO log & make timeout configurable197 callback(null, false);198 }, 100);199 var d = domain.create();200 d.run(function() {201 pb.log.debug('System[%s]: Calling [%s] shutdown hook', self.getWorkerId(), keys[i]);202 SHUTDOWN_HOOKS[keys[i]](function(err, result) {203 if (timeoutHandle) {204 clearTimeout(timeoutHandle);205 timeoutHandle = null;206 callback(null, result);207 }208 });209 });210 d.on('error', function(err) {211 if (timeoutHandle) {212 clearTimeout(timeoutHandle);213 timeoutHandle = null;214 }215 //TODO log216 callback(null, false);217 });218 };219 });220 async.parallel(tasks.reverse(), function(err, results) {221 pb.log.info('System[%s]: Shutdown complete', self.getWorkerId());222 if (toh) {223 clearTimeout(toh);224 toh = null;225 }226 227 //kill off the process when instructed228 if (killProcess) {229 process.exit();230 }231 });232 //create fallback so that when services do not shutdown within 5 seconds the process is forced to terminate233 if (killProcess) {234 toh = setTimeout(function() {235 log.info("System[%s]: Shutdown completed but was forced", self.getWorkerId());236 process.exit();237 }, FORCE_PROCESS_EXIT_TIMEOUT);238 }239 240 };241 242 /**243 * Registers signal handlers (SIGTERM, SIGINT) that will call shutdown when 244 * triggered245 * @method registerSignalHandlers246 * @param {Boolean} [killProcess] When TRUE or not provided the variable 247 * instructs the handlers to kill off the process in addition to shutting 248 * down PencilBlue services249 */250 this.registerSignalHandlers = function(killProcess) {251 var self = this;252 253 //determine if th process should be killed off254 killProcess = killProcess || util.isNullOrUndefined(killProcess);255 256 // listen for TERM signal .e.g. kill257 process.on ('SIGTERM', function() {258 log.debug('System[%s]: SIGTERM detected %s', self.getWorkerId(), IS_SHUTTING_DOWN ? 'but is already shutting down' : '');259 if (!IS_SHUTTING_DOWN) {260 self.shutdown(killProcess);261 }262 });263 // listen for INT signal e.g. Ctrl-C264 process.on ('SIGINT', function() {265 log.debug('System[%s]: SIGINT detected %s', self.getWorkerId(), IS_SHUTTING_DOWN ? 'but is already shutting down' : '');266 if (!IS_SHUTTING_DOWN) {267 self.shutdown(killProcess);268 }269 });270 };...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var workerId = $rootScope.getWorkerId();2var workerId = $scope.getWorkerId();3var workerId = controller.getWorkerId();4var workerId = service.getWorkerId();5var workerId = factory.getWorkerId();6var workerId = provider.getWorkerId();7$rootScope.getWorkerId()8.then(function(workerId) {9})10.catch(function(error) {11});12$scope.getWorkerId()13.then(function(workerId) {14})15.catch(function(error) {16});17controller.getWorkerId()18.then(function(workerId) {19})20.catch(function(error) {21});22service.getWorkerId()23.then(function(workerId) {24})25.catch(function(error) {26});27factory.getWorkerId()28.then(function(workerId) {29})30.catch(function(error) {31});32provider.getWorkerId()33.then(function(workerId) {34})35.catch(function(error) {36});37$rootScope.getWorkerId()38.then(function(workerId) {39}, function(error) {40});41$scope.getWorkerId()42.then(function(workerId) {43}, function(error) {44});45controller.getWorkerId()46.then(function(workerId

Full Screen

Using AI Code Generation

copy

Full Screen

1var workerId = $rootScope.getWorkerId();2var workerId = $rootScope.getWorkerId();3var workerId = $rootScope.getWorkerId();4var workerId = $rootScope.getWorkerId();5var workerId = $rootScope.getWorkerId();6var workerId = $rootScope.getWorkerId();7var workerId = $rootScope.getWorkerId();8var workerId = $rootScope.getWorkerId();9var workerId = $rootScope.getWorkerId();

Full Screen

Using AI Code Generation

copy

Full Screen

1const workerId = yield getWorkerId();2### `getWorkerId()`3### `getWorkerCount()`4### `getWorkerStatus()`5### `getWorkerStatusById(id)`6### `getWorkerStatusByIndex(index)`7### `getWorkerStatuses()`8### `getWorkerIds()`9### `getWorkerIdsByStatus(status)`10### `getWorkerIndexById(id)`11### `getWorkerIdByIndex(index)`12### `getWorkerIdsByStatus(status)`13### `getWorkerIndexById(id)`14### `getWorkerIdByIndex(index)`15### `getWorkerIndexByStatus(status)`16### `getWorkerIdByStatus(status)`17### `killWorker(id)`18### `killWorkerByIndex(index)`19### `killWorkerByStatus(status)`

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run root automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful