Add TASK_ERROR reason code

This commit is contained in:
Girish Ramakrishnan
2019-09-19 23:13:04 -07:00
parent 89ff6be971
commit 2942da78de
2 changed files with 4 additions and 6 deletions

View File

@@ -63,10 +63,6 @@ exports = module.exports = {
PORT_TYPE_TCP: 'tcp',
PORT_TYPE_UDP: 'udp',
// error codes
ETASK_STOPPED: 'task_stopped', // user stopped a task
ETASK_CRASHED: 'task_crashed', // apptask crashed
// installation codes (keep in sync in UI)
ISTATE_PENDING_INSTALL: 'pending_install', // installs and fresh reinstalls
ISTATE_PENDING_CLONE: 'pending_clone', // clone
@@ -110,6 +106,7 @@ var appdb = require('./appdb.js'),
async = require('async'),
backups = require('./backups.js'),
BackupsError = backups.BackupsError,
BoxError = require('./boxerror.js'),
constants = require('./constants.js'),
DatabaseError = require('./databaseerror.js'),
debug = require('debug')('box:apps'),
@@ -647,8 +644,8 @@ function scheduleTask(appId, args, values, callback) {
debug(`scheduleTask: task ${taskId} of $${appId} completed`);
if (error && (error.code === tasks.ECRASHED || error.code === tasks.ESTOPPED)) { // if task crashed, update the error
debug(`Apptask crashed/stopped: ${error.message}`);
const code = error.crashed ? exports.ETASK_CRASHED : exports.ETASK_STOPPED;
appdb.update(appId, { installationState: exports.ISTATE_ERROR, error: { code: code, message: error.message }, taskId: null }, NOOP_CALLBACK);
const crashed = error.code === tasks.ECRASHED, stopped = error.code === tasks.ESTOPPED;
appdb.update(appId, { installationState: exports.ISTATE_ERROR, error: { reason: BoxError.TASK_ERROR, crashed, stopped, message: error.message }, taskId: null }, NOOP_CALLBACK);
} else if (values.installationState !== exports.ISTATE_PENDING_UNINSTALL) { // clear out taskId since it's done
appdb.update(appId, { taskId: null }, NOOP_CALLBACK);
}