mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-25 10:22:55 +08: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();
|
timerStub.reset();
|
||||||
|
|
||||||
await t.throwsAsync(
|
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',
|
message: 'Throw in job handler',
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,7 +58,8 @@ export class JobExecutor implements OnModuleDestroy {
|
|||||||
|
|
||||||
async run<T extends JobName>(
|
async run<T extends JobName>(
|
||||||
name: T,
|
name: T,
|
||||||
payload: Jobs[T]
|
payload: Jobs[T],
|
||||||
|
jobId?: string
|
||||||
): Promise<JOB_SIGNAL | undefined> {
|
): Promise<JOB_SIGNAL | undefined> {
|
||||||
const ns = namespace(name);
|
const ns = namespace(name);
|
||||||
const handler = this.scanner.getHandler(name);
|
const handler = this.scanner.getHandler(name);
|
||||||
@@ -70,7 +71,7 @@ export class JobExecutor implements OnModuleDestroy {
|
|||||||
|
|
||||||
const fn = wrapCallMetric(
|
const fn = wrapCallMetric(
|
||||||
async () => {
|
async () => {
|
||||||
const signature = `[${name}] (${handler.name})`;
|
const signature = `[${name}] (${handler.name}, id=${jobId})`;
|
||||||
try {
|
try {
|
||||||
this.logger.debug(`Job started: ${signature}`);
|
this.logger.debug(`Job started: ${signature}`);
|
||||||
const ret = await handler.fn(payload);
|
const ret = await handler.fn(payload);
|
||||||
@@ -129,7 +130,7 @@ export class JobExecutor implements OnModuleDestroy {
|
|||||||
|
|
||||||
return await cls.run(async () => {
|
return await cls.run(async () => {
|
||||||
cls.set(CLS_ID, requestId);
|
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, {
|
merge({}, this.config.job.queue, this.config.job.worker, queueOptions, {
|
||||||
|
|||||||
Reference in New Issue
Block a user