remove console.error use in many places
the backtraces just flood the logs apphealthtask: remove console.error remove spurious console.dir cleanup scheduler error logging
This commit is contained in:
@@ -13,27 +13,21 @@ let apps = require('./apps.js'),
|
||||
docker = require('./docker.js'),
|
||||
_ = require('underscore');
|
||||
|
||||
var NOOP_CALLBACK = function (error) { if (error) debug('Unhandled error: ', error); };
|
||||
|
||||
// appId -> { schedulerConfig (manifest), cronjobs }
|
||||
var gState = { };
|
||||
|
||||
function sync(callback) {
|
||||
assert(!callback || typeof callback === 'function');
|
||||
|
||||
callback = callback || NOOP_CALLBACK;
|
||||
|
||||
function sync() {
|
||||
apps.getAll(function (error, allApps) {
|
||||
if (error) return callback(error);
|
||||
if (error) return debug(`sync: error getting app list. ${error.message}`);
|
||||
|
||||
var allAppIds = allApps.map(function (app) { return app.id; });
|
||||
var removedAppIds = _.difference(Object.keys(gState), allAppIds);
|
||||
if (removedAppIds.length !== 0) debug('sync: stopping jobs of removed apps %j', removedAppIds);
|
||||
if (removedAppIds.length !== 0) debug(`sync: stopping jobs of removed apps ${JSON.stringify(removedAppIds)}`);
|
||||
|
||||
async.eachSeries(removedAppIds, function (appId, iteratorDone) {
|
||||
stopJobs(appId, gState[appId], iteratorDone);
|
||||
}, function (error) {
|
||||
if (error) debug('sync: error stopping jobs of removed apps', error);
|
||||
if (error) debug(`sync: error stopping jobs of removed apps: ${error.message}`);
|
||||
|
||||
gState = _.omit(gState, removedAppIds);
|
||||
|
||||
@@ -48,7 +42,7 @@ function sync(callback) {
|
||||
}
|
||||
|
||||
stopJobs(app.id, appState, function (error) {
|
||||
if (error) debug(`sync: error stopping jobs of ${app.fqdn} : ${error.message}`);
|
||||
if (error) debug(`sync: error stopping jobs of ${app.id} : ${error.message}`);
|
||||
|
||||
if (!schedulerConfig) {
|
||||
delete gState[app.id];
|
||||
@@ -75,7 +69,7 @@ function killContainer(containerName, callback) {
|
||||
docker.stopContainerByName.bind(null, containerName),
|
||||
docker.deleteContainerByName.bind(null, containerName)
|
||||
], function (error) {
|
||||
if (error) debug('Failed to kill task with name %s : %s', containerName, error.message);
|
||||
if (error) debug(`killContainer: failed to kill task with name ${containerName} : ${error.message}`);
|
||||
|
||||
callback(error);
|
||||
});
|
||||
@@ -101,6 +95,7 @@ function createCronJobs(app, schedulerConfig) {
|
||||
assert.strictEqual(typeof app, 'object');
|
||||
assert(schedulerConfig && typeof schedulerConfig === 'object');
|
||||
|
||||
const appId = app.id;
|
||||
var jobs = { };
|
||||
|
||||
Object.keys(schedulerConfig).forEach(function (taskName) {
|
||||
@@ -112,7 +107,9 @@ function createCronJobs(app, schedulerConfig) {
|
||||
|
||||
var cronJob = new CronJob({
|
||||
cronTime: cronTime, // at this point, the pattern has been validated
|
||||
onTick: runTask.bind(null, app.id, taskName), // put the app id in closure, so we don't use the outdated app object by mistake
|
||||
onTick: () => runTask(appId, taskName, (error) => { // put the app id in closure, so we don't use the outdated app object by mistake
|
||||
if (error) debug(`could not run task ${taskName} : ${error.message}`);
|
||||
}),
|
||||
start: true
|
||||
});
|
||||
|
||||
@@ -125,12 +122,10 @@ function createCronJobs(app, schedulerConfig) {
|
||||
function runTask(appId, taskName, callback) {
|
||||
assert.strictEqual(typeof appId, 'string');
|
||||
assert.strictEqual(typeof taskName, 'string');
|
||||
assert(!callback || typeof callback === 'function');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
const JOB_MAX_TIME = 30 * 60 * 1000; // 30 minutes
|
||||
|
||||
callback = callback || NOOP_CALLBACK;
|
||||
|
||||
apps.get(appId, function (error, app) {
|
||||
if (error) return callback(error);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user