replace debug() with our custom logger
mostly we want trace() and log(). trace() can be enabled whenever we want by flipping a flag and restarting box
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import assert from 'node:assert';
|
||||
import BoxError from './boxerror.js';
|
||||
import debugModule from 'debug';
|
||||
import logger from './logger.js';
|
||||
import fs from 'node:fs';
|
||||
import locks from './locks.js';
|
||||
import path from 'node:path';
|
||||
@@ -9,7 +9,7 @@ import safe from 'safetydance';
|
||||
import scheduler from './scheduler.js';
|
||||
import tasks from './tasks.js';
|
||||
|
||||
const debug = debugModule('box:apptaskmanager');
|
||||
const { log, trace } = logger('apptaskmanager');
|
||||
|
||||
|
||||
const gActiveTasks = {}; // indexed by app id
|
||||
@@ -22,12 +22,12 @@ const DRAIN_TIMER_SECS = 1000;
|
||||
let gDrainTimerId = null;
|
||||
|
||||
async function drain() {
|
||||
debug(`drain: ${gPendingTasks.length} apptasks pending`);
|
||||
log(`drain: ${gPendingTasks.length} apptasks pending`);
|
||||
|
||||
for (let i = 0; i < gPendingTasks.length; i++) {
|
||||
const space = Object.keys(gActiveTasks).length - TASK_CONCURRENCY;
|
||||
if (space == 0) {
|
||||
debug('At concurrency limit, cannot drain anymore');
|
||||
log('At concurrency limit, cannot drain anymore');
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ async function drain() {
|
||||
.catch((error) => { taskError = error; })
|
||||
.finally(async () => {
|
||||
delete gActiveTasks[appId];
|
||||
await safe(onFinished(taskError, taskResult), { debug }); // hasPendingTasks() can now return false
|
||||
await safe(onFinished(taskError, taskResult), { debug: log }); // hasPendingTasks() can now return false
|
||||
await locks.release(`${locks.TYPE_APP_TASK_PREFIX}${appId}`);
|
||||
await locks.releaseByTaskId(taskId);
|
||||
scheduler.resumeAppJobs(appId);
|
||||
@@ -68,7 +68,7 @@ async function start() {
|
||||
assert.strictEqual(gDrainTimerId, null);
|
||||
assert.strictEqual(gStarted, false);
|
||||
|
||||
debug('started');
|
||||
log('started');
|
||||
gStarted = true;
|
||||
|
||||
if (gPendingTasks.length) gDrainTimerId = setTimeout(drain, DRAIN_TIMER_SECS);
|
||||
|
||||
Reference in New Issue
Block a user