Skip to content

Commit

Permalink
handle throttle failure
Browse files Browse the repository at this point in the history
  • Loading branch information
f-w committed Dec 6, 2024
1 parent 98b0687 commit aa60f61
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ import { RssModule } from './rss/rss.module';
prefix: 'nb',
defaultJobOptions: {
removeOnComplete: true,
removeOnFail: true,
},
};
const connection = appConfigService.get('queue.connection');
Expand Down
9 changes: 6 additions & 3 deletions src/common/common.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ export class CommonService {
prefix: queue.opts.prefix,
});
const queuedID = [];
// IMPORTANT: place queueEvents.on before myQueue.add
queueEvents.on('completed', async ({ jobId }) => {
const queueEventHandler = async ({ jobId }) => {
if (!j?.id) {
queuedID.push(jobId);
return;
Expand All @@ -95,7 +94,11 @@ export class CommonService {
reject(ex);
}
queueEvents.close();
});
};
// IMPORTANT: place queueEvents.on before myQueue.add
queueEvents.on('completed', queueEventHandler);
queueEvents.on('failed', queueEventHandler);

await queueEvents.waitUntilReady();
const j = await queue.add('', undefined, { priority: opts.priority });
// extra guard in case queueEvents.on is called before j is assigned.
Expand Down

0 comments on commit aa60f61

Please sign in to comment.