Fix usage of eventlog.add

This commit is contained in:
Girish Ramakrishnan
2021-06-03 11:42:32 -07:00
parent 2c1bedd38a
commit c90a9e43cf
5 changed files with 21 additions and 24 deletions

View File

@@ -56,12 +56,10 @@ const REBOOT_CMD = path.join(__dirname, 'scripts/reboot.sh');
const NOOP_CALLBACK = function (error) { if (error) debug(error); };
function initialize(callback) {
assert.strictEqual(typeof callback, 'function');
async function initialize() {
runStartupTasks();
notifyUpdate(callback);
await notifyUpdate();
}
function uninitialize(callback) {
@@ -97,21 +95,19 @@ function onActivated(options, callback) {
], callback);
}
function notifyUpdate(callback) {
assert.strictEqual(typeof callback, 'function');
async function notifyUpdate() {
const version = safe.fs.readFileSync(paths.VERSION_FILE, 'utf8');
if (version === constants.VERSION) return callback();
if (version === constants.VERSION) return;
eventlog.add(eventlog.ACTION_UPDATE_FINISH, auditSource.CRON, { errorMessage: '', oldVersion: version || 'dev', newVersion: constants.VERSION }, function (error) {
if (error) return callback(error);
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 callback(error); // when hotfixing, task may not exist
if (error && error.reason !== BoxError.NOT_FOUND) return reject(error); // when hotfixing, task may not exist
safe.fs.writeFileSync(paths.VERSION_FILE, constants.VERSION, 'utf8');
callback();
resolve();
});
});
}