merge taskdb into tasks.js

This commit is contained in:
Girish Ramakrishnan
2021-07-12 23:35:30 -07:00
parent db685d3a56
commit e59d0e878d
18 changed files with 487 additions and 669 deletions
+16 -32
View File
@@ -95,15 +95,10 @@ async function notifyUpdate() {
await eventlog.add(eventlog.ACTION_UPDATE_FINISH, auditSource.CRON, { errorMessage: '', oldVersion: version || 'dev', newVersion: constants.VERSION });
return new Promise((resolve, reject) => {
tasks.setCompletedByType(tasks.TASK_UPDATE, { error: null }, function (error) {
if (error && error.reason !== BoxError.NOT_FOUND) return reject(error); // when hotfixing, task may not exist
const [error] = await safe(tasks.setCompletedByType(tasks.TASK_UPDATE, { error: null }));
if (error && error.reason !== BoxError.NOT_FOUND) throw error; // when hotfixing, task may not exist
safe.fs.writeFileSync(paths.VERSION_FILE, constants.VERSION, 'utf8');
resolve();
});
});
safe.fs.writeFileSync(paths.VERSION_FILE, constants.VERSION, 'utf8');
}
// each of these tasks can fail. we will add some routes to fix/re-run them
@@ -291,19 +286,18 @@ function prepareDashboardDomain(domain, auditSource, callback) {
const fqdn = domains.fqdn(constants.DASHBOARD_LOCATION, domainObject);
apps.getAll(function (error, result) {
apps.getAll(async function (error, result) {
if (error) return callback(error);
const conflict = result.filter(app => app.fqdn === fqdn);
if (conflict.length) return callback(new BoxError(BoxError.BAD_STATE, 'Dashboard location conflicts with an existing app'));
tasks.add(tasks.TASK_SETUP_DNS_AND_CERT, [ constants.DASHBOARD_LOCATION, domain, auditSource ], function (error, taskId) {
if (error) return callback(error);
const [taskError, taskId] = await safe(tasks.add(tasks.TASK_SETUP_DNS_AND_CERT, [ constants.DASHBOARD_LOCATION, domain, auditSource ]));
if (taskError) return callback(taskError);
tasks.startTask(taskId, {}, NOOP_CALLBACK);
tasks.startTask(taskId, {}, NOOP_CALLBACK);
callback(null, taskId);
});
callback(null, taskId);
});
});
}
@@ -356,18 +350,13 @@ function updateDashboardDomain(domain, auditSource, callback) {
});
}
function renewCerts(options, auditSource, callback) {
async function renewCerts(options, auditSource) {
assert.strictEqual(typeof options, 'object');
assert.strictEqual(typeof auditSource, 'object');
assert.strictEqual(typeof callback, 'function');
tasks.add(tasks.TASK_CHECK_CERTS, [ options, auditSource ], function (error, taskId) {
if (error) return callback(error);
tasks.startTask(taskId, {}, NOOP_CALLBACK);
callback(null, taskId);
});
const taskId = await tasks.add(tasks.TASK_CHECK_CERTS, [ options, auditSource ]);
tasks.startTask(taskId, {}, NOOP_CALLBACK);
return taskId;
}
function setupDnsAndCert(subdomain, domain, auditSource, progressCallback, callback) {
@@ -401,15 +390,10 @@ function setupDnsAndCert(subdomain, domain, auditSource, progressCallback, callb
});
}
function syncDnsRecords(options, callback) {
async function syncDnsRecords(options) {
assert.strictEqual(typeof options, 'object');
assert.strictEqual(typeof callback, 'function');
tasks.add(tasks.TASK_SYNC_DNS_RECORDS, [ options ], function (error, taskId) {
if (error) return callback(error);
tasks.startTask(taskId, {}, NOOP_CALLBACK);
callback(null, taskId);
});
const taskId = await tasks.add(tasks.TASK_SYNC_DNS_RECORDS, [ options ]);
tasks.startTask(taskId, {}, NOOP_CALLBACK);
return taskId;
}