mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 20:38:52 +00:00
chore(server): print jobId (#12593)
Need to query the payload through job id for debugging <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Tests** - Updated job metrics test to include an explicit job ID during execution. - **Refactor** - Enhanced job execution to support an optional job ID, improving job tracking and logging. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -168,7 +168,7 @@ test('should be able to record job metrics', async t => {
|
||||
timerStub.reset();
|
||||
|
||||
await t.throwsAsync(
|
||||
executor.run('nightly.__test__throw', { name: 'test executor' }),
|
||||
executor.run('nightly.__test__throw', { name: 'test executor' }, 'test-id'),
|
||||
{
|
||||
message: 'Throw in job handler',
|
||||
}
|
||||
|
||||
@@ -58,7 +58,8 @@ export class JobExecutor implements OnModuleDestroy {
|
||||
|
||||
async run<T extends JobName>(
|
||||
name: T,
|
||||
payload: Jobs[T]
|
||||
payload: Jobs[T],
|
||||
jobId?: string
|
||||
): Promise<JOB_SIGNAL | undefined> {
|
||||
const ns = namespace(name);
|
||||
const handler = this.scanner.getHandler(name);
|
||||
@@ -70,7 +71,7 @@ export class JobExecutor implements OnModuleDestroy {
|
||||
|
||||
const fn = wrapCallMetric(
|
||||
async () => {
|
||||
const signature = `[${name}] (${handler.name})`;
|
||||
const signature = `[${name}] (${handler.name}, id=${jobId})`;
|
||||
try {
|
||||
this.logger.debug(`Job started: ${signature}`);
|
||||
const ret = await handler.fn(payload);
|
||||
@@ -129,7 +130,7 @@ export class JobExecutor implements OnModuleDestroy {
|
||||
|
||||
return await cls.run(async () => {
|
||||
cls.set(CLS_ID, requestId);
|
||||
return await this.run(job.name as JobName, payload);
|
||||
return await this.run(job.name as JobName, payload, job.id);
|
||||
});
|
||||
},
|
||||
merge({}, this.config.job.queue, this.config.job.worker, queueOptions, {
|
||||
|
||||
Reference in New Issue
Block a user