chore(server): add prefix to indexer jobId (#12369)

This commit is contained in:
fengmk2
2025-05-20 03:09:23 +00:00
parent 9ad76fe2f6
commit 8e9d50bfe9
2 changed files with 20 additions and 11 deletions

View File

@@ -36,7 +36,7 @@ export class DocEventsListener {
docId, docId,
}, },
{ {
jobId: `${workspaceId}/${docId}`, jobId: `indexDoc/${workspaceId}/${docId}`,
priority: 100, priority: 100,
} }
); );
@@ -53,7 +53,7 @@ export class DocEventsListener {
workspaceId, workspaceId,
}, },
{ {
jobId: workspaceId, jobId: `indexWorkspace/${workspaceId}`,
priority: 100, priority: 100,
} }
); );
@@ -70,7 +70,7 @@ export class DocEventsListener {
workspaceId: workspace, workspaceId: workspace,
}, },
{ {
jobId: workspace, jobId: `deleteWorkspace/${workspace}`,
priority: 0, priority: 0,
} }
); );

View File

@@ -42,14 +42,20 @@ export class IndexerJob {
@OnJob('indexer.indexDoc') @OnJob('indexer.indexDoc')
async indexDoc({ workspaceId, docId }: Jobs['indexer.indexDoc']) { async indexDoc({ workspaceId, docId }: Jobs['indexer.indexDoc']) {
// delete the 'indexer.deleteDoc' job from the queue // delete the 'indexer.deleteDoc' job from the queue
await this.queue.remove(`${workspaceId}/${docId}`, 'indexer.deleteDoc'); await this.queue.remove(
`deleteDoc/${workspaceId}/${docId}`,
'indexer.deleteDoc'
);
await this.service.indexDoc(workspaceId, docId); await this.service.indexDoc(workspaceId, docId);
} }
@OnJob('indexer.deleteDoc') @OnJob('indexer.deleteDoc')
async deleteDoc({ workspaceId, docId }: Jobs['indexer.deleteDoc']) { async deleteDoc({ workspaceId, docId }: Jobs['indexer.deleteDoc']) {
// delete the 'indexer.updateDoc' job from the queue // delete the 'indexer.updateDoc' job from the queue
await this.queue.remove(`${workspaceId}/${docId}`, 'indexer.indexDoc'); await this.queue.remove(
`indexDoc/${workspaceId}/${docId}`,
'indexer.indexDoc'
);
await this.service.deleteDoc(workspaceId, docId); await this.service.deleteDoc(workspaceId, docId);
} }
@@ -91,8 +97,8 @@ export class IndexerJob {
docId, docId,
}, },
{ {
jobId: `${workspaceId}/${docId}`, jobId: `deleteDoc/${workspaceId}/${docId}`,
// the delete job should be higher priority than the update job // the deleteDoc job should be higher priority than the indexDoc job
priority: 0, priority: 0,
} }
); );
@@ -105,7 +111,7 @@ export class IndexerJob {
docId, docId,
}, },
{ {
jobId: `${workspaceId}/${docId}`, jobId: `indexDoc/${workspaceId}/${docId}`,
priority: 100, priority: 100,
} }
); );
@@ -122,7 +128,10 @@ export class IndexerJob {
@OnJob('indexer.deleteWorkspace') @OnJob('indexer.deleteWorkspace')
async deleteWorkspace({ workspaceId }: Jobs['indexer.deleteWorkspace']) { async deleteWorkspace({ workspaceId }: Jobs['indexer.deleteWorkspace']) {
await this.queue.remove(workspaceId, 'indexer.indexWorkspace'); await this.queue.remove(
`indexWorkspace/${workspaceId}`,
'indexer.indexWorkspace'
);
await this.service.deleteWorkspace(workspaceId); await this.service.deleteWorkspace(workspaceId);
} }
@@ -159,7 +168,7 @@ export class IndexerJob {
await this.queue.add( await this.queue.add(
'indexer.indexWorkspace', 'indexer.indexWorkspace',
{ workspaceId: workspace.id }, { workspaceId: workspace.id },
{ jobId: workspace.id } { jobId: `indexWorkspace/${workspace.id}` }
); );
addedCount++; addedCount++;
} }
@@ -184,7 +193,7 @@ export class IndexerJob {
{ {
// make sure only one job is running at a time // make sure only one job is running at a time
delay: 30 * 1000, delay: 30 * 1000,
jobId: 'indexer:auto-index-workspaces', jobId: 'autoIndexWorkspaces',
} }
); );
} }