more async'ification

This commit is contained in:
Girish Ramakrishnan
2021-09-07 09:57:49 -07:00
parent e7f51d992f
commit 7709e155e0
15 changed files with 267 additions and 400 deletions
+10 -15
View File
@@ -65,13 +65,9 @@ async function initialize() {
await notifyUpdate();
}
function uninitialize(callback) {
assert.strictEqual(typeof callback, 'function');
async.series([
cron.stopJobs,
platform.stopAllTasks
], callback);
async function uninitialize() {
await cron.stopJobs();
await platform.stopAllTasks();
}
function onActivated(options, callback) {
@@ -217,10 +213,9 @@ async function checkUbuntuVersion() {
await notifications.alert(notifications.ALERT_UPDATE_UBUNTU, 'Ubuntu upgrade required', 'Ubuntu 16.04 has reached end of life and will not receive security and maintenance updates. Please follow https://docs.cloudron.io/guides/upgrade-ubuntu-18/ to upgrade to Ubuntu 18 at the earliest.');
}
function getLogs(unit, options, callback) {
async function getLogs(unit, options) {
assert.strictEqual(typeof unit, 'string');
assert(options && typeof options === 'object');
assert.strictEqual(typeof callback, 'function');
assert.strictEqual(typeof options.lines, 'number');
assert.strictEqual(typeof options.format, 'string');
@@ -238,15 +233,15 @@ function getLogs(unit, options, callback) {
// need to handle box.log without subdir
if (unit === 'box') args.push(path.join(paths.LOG_DIR, 'box.log'));
else if (unit.startsWith('crash-')) args.push(path.join(paths.CRASH_LOG_DIR, unit.slice(6) + '.log'));
else return callback(new BoxError(BoxError.BAD_FIELD, 'No such unit', { field: 'unit' }));
else throw new BoxError(BoxError.BAD_FIELD, 'No such unit', { field: 'unit' });
var cp = spawn('/usr/bin/tail', args);
const cp = spawn('/usr/bin/tail', args);
var transformStream = split(function mapper(line) {
const transformStream = split(function mapper(line) {
if (format !== 'json') return line + '\n';
var data = line.split(' '); // logs are <ISOtimestamp> <msg>
var timestamp = (new Date(data[0])).getTime();
const data = line.split(' '); // logs are <ISOtimestamp> <msg>
let timestamp = (new Date(data[0])).getTime();
if (isNaN(timestamp)) timestamp = 0;
return JSON.stringify({
@@ -260,7 +255,7 @@ function getLogs(unit, options, callback) {
cp.stdout.pipe(transformStream);
return callback(null, transformStream);
return transformStream;
}
async function prepareDashboardDomain(domain, auditSource) {