Пример #1
0
JobBase.prototype.start = function() {
	if (this.running) {
		this.stop();
	}
	this.running = true;

	logger.trace('Starting job, id:', this.id);
	var self = this;
	this.innerJob = setTimeout(function onStartTimeout() { onTimeout(self, self.interval); }, this.startIn);

	// Metrics
	if (this.metricsBucket) {
		if (!metrics.isRegisteredGauge(this.metricsBucket)) {
			metrics.registerGauge(this.metricsBucket);
		}

		metrics.changeGauge(this.metricsBucket, +1);
	}
};
Пример #2
0
JobBase.prototype.stop = function() {
	if (!this.running) {
		return;
	}

	logger.trace('Stopping job, id:', this.id);

	if (this.innerJob) {
		clearTimeout(this.innerJob);
		this.innerJob = null;
	}

	this.running = false;

	// Metrics
	if (this.metricsBucket && metrics.isRegisteredGauge(this.metricsBucket)) {
		var remaining = metrics.changeGauge(this.metricsBucket, -1);
		if (remaining === 0) {
			metrics.unregisterGauge(this.metricsBucket);
		}
	}
};