BREAKING CHANGE(taskbuffer): Change default Task error handling: trigger() now rejects when taskFunction throws; add catchErrors option (default false) to preserve previous swallow behavior; track errors (lastError, errorCount) and expose them in metadata; improve error propagation and logging across runners, chains, parallels and debounced tasks; add tests and documentation for new behavior.

This commit is contained in:
2026-01-25 23:29:00 +00:00
parent 905ca97b6a
commit 248383aab1
16 changed files with 575 additions and 63 deletions

View File

@@ -5,6 +5,7 @@ import {
type IDistributedTaskRequestResult,
} from './taskbuffer.classes.distributedcoordinator.js';
import type { ITaskMetadata, ITaskExecutionReport, IScheduledTaskInfo } from './taskbuffer.interfaces.js';
import { logger } from './taskbuffer.logging.js';
export interface ICronJob {
cronString: string;
@@ -75,31 +76,35 @@ export class TaskManager {
triggerTime,
);
if (!announcementResult.shouldTrigger) {
console.log('Distributed coordinator result: NOT EXECUTING');
logger.log('info', 'Distributed coordinator result: NOT EXECUTING');
return;
} else {
console.log('Distributed coordinator result: CHOSEN AND EXECUTING');
logger.log('info', 'Distributed coordinator result: CHOSEN AND EXECUTING');
}
}
await task.trigger();
try {
await task.trigger();
} catch (err) {
logger.log('error', `TaskManager: scheduled task "${task.name || 'unnamed'}" failed: ${err instanceof Error ? err.message : String(err)}`);
}
},
);
task.cronJob = cronJob;
}
private logTaskState(task: Task<any, any>) {
console.log(`Taskbuffer schedule triggered task >>${task.name}<<`);
logger.log('info', `Taskbuffer schedule triggered task >>${task.name}<<`);
const bufferState = task.buffered
? `buffered with max ${task.bufferMax} buffered calls`
: `unbuffered`;
console.log(`Task >>${task.name}<< is ${bufferState}`);
logger.log('info', `Task >>${task.name}<< is ${bufferState}`);
}
private async performDistributedConsultation(
task: Task<any, any>,
triggerTime: number,
): Promise<IDistributedTaskRequestResult> {
console.log('Found a distributed coordinator, performing consultation.');
logger.log('info', 'Found a distributed coordinator, performing consultation.');
return this.options.distributedCoordinator.fireDistributedTaskRequest({
submitterId: this.randomId,