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:
14
src/apps.js
14
src/apps.js
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user