rework task API to be two-phase

this lets us avoid this EE based API. we now add and then start
explicitly.
This commit is contained in:
Girish Ramakrishnan
2019-08-27 22:39:59 -07:00
parent c6be0b290b
commit b30ff1f55a
7 changed files with 231 additions and 211 deletions

View File

@@ -126,6 +126,8 @@ AppsError.PLAN_LIMIT = 'Plan Limit';
AppsError.ACCESS_DENIED = 'Access denied';
AppsError.BAD_CERTIFICATE = 'Invalid certificate';
const NOOP_CALLBACK = function (error) { if (error) debug(error); };
// validate the port bindings
function validatePortBindings(portBindings, manifest) {
assert.strictEqual(typeof portBindings, 'object');
@@ -578,19 +580,17 @@ function startAppTask(appId, args, callback) {
if (!fs.existsSync(path.dirname(logFile))) safe.fs.mkdirSync(path.dirname(logFile)); // ensure directory
let task = tasks.startTask(tasks.TASK_APP, [ appId, args ], { logFile });
task.on('start', function (taskId) {
tasks.add(tasks.TASK_APP, [ appId, args ], function (error, taskId) {
if (error) return callback(new AppsError(AppsError.INTERNAL_ERROR, error));
appdb.update(appId, { taskId: taskId }, function (error) {
if (error) return callback(new AppsError(AppsError.INTERNAL_ERROR, error));
get(appId, function (error, result) {
if (error) return callback(error);
tasks.startTask(taskId, { logFile }, NOOP_CALLBACK);
callback(null, result);
});
callback(null, taskId);
});
});
task.on('error', (error) => callback(new AppsError(AppsError.INTERNAL_ERROR, error)));
}
function install(data, user, auditSource, callback) {