Skip to content

Commit

Permalink
chore(worker): capture errors and retry limit
Browse files Browse the repository at this point in the history
  • Loading branch information
awinogradov committed Aug 16, 2023
1 parent d3f937e commit ed6b8f6
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/utils/worker/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { PrismaClient } from '@prisma/client';
import * as Sentry from '@sentry/nextjs';

import { JobDataMap, JobKind, jobKind, jobState } from './create';
import * as resolve from './resolve';
Expand All @@ -20,6 +21,10 @@ console.log('Worker started successfully');
},
});

if (jobs.length > 300) {
Sentry.captureMessage('Queue too long. Smth went wrong.');
}

jobs.forEach(async (job) => {
if (job.state === jobState.completed) {
setTimeout(async () => {
Expand All @@ -46,6 +51,15 @@ console.log('Worker started successfully');
data: { state: jobState.scheduled, error: error?.message, retry },
});
}, retry * defaultJobDelay);
} else {
Sentry.captureException(error, {
fingerprint: ['worker', 'resolve', 'retry'],
extra: {
job,
},
});

await prisma.job.delete({ where: { id: job.id } });
}
}
}, job.delay || defaultJobDelay);
Expand Down

0 comments on commit ed6b8f6

Please sign in to comment.