apptask is not a separate process anymore

This commit is contained in:
Girish Ramakrishnan
2019-08-27 10:11:41 -07:00
parent aecb99b6a3
commit e560c18b57
2 changed files with 0 additions and 77 deletions

View File

@@ -3,9 +3,6 @@
'use strict';
exports = module.exports = {
initialize: initialize,
startTask: startTask,
run: run,
// exported for testing
@@ -30,7 +27,6 @@ var addons = require('./addons.js'),
auditsource = require('./auditsource.js'),
backups = require('./backups.js'),
constants = require('./constants.js'),
database = require('./database.js'),
DatabaseError = require('./databaseerror.js'),
debug = require('debug')('box:apptask'),
df = require('@sindresorhus/df'),
@@ -62,15 +58,6 @@ var COLLECTD_CONFIG_EJS = fs.readFileSync(__dirname + '/collectd.config.ejs', {
LOGROTATE_CONFIG_EJS = fs.readFileSync(__dirname + '/logrotate.ejs', { encoding: 'utf8' }),
CONFIGURE_LOGROTATE_CMD = path.join(__dirname, 'scripts/configurelogrotate.sh');
function initialize(callback) {
assert.strictEqual(typeof callback, 'function');
async.series([
database.initialize,
settings.initCache
], callback);
}
function debugApp(app) {
assert.strictEqual(typeof app, 'object');
@@ -918,40 +905,6 @@ function handleRunCommand(app, progressCallback, callback) {
return callback(null);
}
function startTask(appId, callback) {
assert.strictEqual(typeof appId, 'string');
assert.strictEqual(typeof callback, 'function');
// determine what to do
apps.get(appId, function (error, app) {
if (error) return callback(error);
debugApp(app, 'startTask installationState: %s runState: %s', app.installationState, app.runState);
switch (app.installationState) {
case appdb.ISTATE_PENDING_UNINSTALL: return uninstall(app, callback);
case appdb.ISTATE_PENDING_CONFIGURE: return configure(app, callback);
case appdb.ISTATE_PENDING_UPDATE: return update(app, callback);
case appdb.ISTATE_PENDING_FORCE_UPDATE: return update(app, callback);
case appdb.ISTATE_PENDING_INSTALL: return install(app, callback);
case appdb.ISTATE_PENDING_CLONE: return install(app, callback);
case appdb.ISTATE_PENDING_RESTORE: return install(app, callback);
case appdb.ISTATE_PENDING_BACKUP: return backup(app, callback);
case appdb.ISTATE_INSTALLED: return handleRunCommand(app, callback);
case appdb.ISTATE_ERROR:
debugApp(app, 'Internal error. apptask launched with error status.');
return callback(null);
default:
debugApp(app, 'apptask launched with invalid command');
return callback(new Error('Unknown command in apptask:' + app.installationState));
}
});
}
function run(appId, progressCallback, callback) {
assert.strictEqual(typeof appId, 'string');
assert.strictEqual(typeof progressCallback, 'function');
@@ -980,29 +933,3 @@ function run(appId, progressCallback, callback) {
}
});
}
if (require.main === module) {
assert.strictEqual(process.argv.length, 3, 'Pass the appid as argument');
// add a separator for the log file
debug('------------------------------------------------------------');
debug('Apptask for %s', process.argv[2]);
process.on('SIGTERM', function () {
debug('taskmanager sent SIGTERM since it got a new task for this app');
process.exit(0);
});
initialize(function (error) {
if (error) throw error;
startTask(process.argv[2], function (error) {
if (error) debug('Apptask completed with error', error);
debug('Apptask completed for %s', process.argv[2]);
// https://nodejs.org/api/process.html are exit codes used by node. apps.js uses the value below
// to check apptask crashes
process.exit(error ? 50 : 0);
});
});
}