Merged
Conversation
This reverts commit 586a10f.
mogery
requested changes
Feb 19, 2025
Member
mogery
left a comment
There was a problem hiding this comment.
some weirdness going on, but overall looks good
Comment on lines
-505
to
-607
| const job = await worker.getNextJob(token); | ||
| if (job) { | ||
| if (job.id) { | ||
| runningJobs.add(job.id); | ||
| } | ||
|
|
||
| async function afterJobDone(job: Job<any, any, string>) { | ||
| try { | ||
| const job = await worker.getNextJob(token); | ||
| if (job) { | ||
| if (job.id) { | ||
| runningJobs.delete(job.id); | ||
| } | ||
|
|
||
| if (job.id && job.data && job.data.team_id && job.data.plan) { | ||
| await removeConcurrencyLimitActiveJob(job.data.team_id, job.id); | ||
| cleanOldConcurrencyLimitEntries(job.data.team_id); | ||
|
|
||
| // Queue up next job, if it exists | ||
| // No need to check if we're under the limit here -- if the current job is finished, | ||
| // we are 1 under the limit, assuming the job insertion logic never over-inserts. - MG | ||
| const nextJob = await takeConcurrencyLimitedJob(job.data.team_id); | ||
| if (nextJob !== null) { | ||
| await pushConcurrencyLimitActiveJob(job.data.team_id, nextJob.id, calculateJobTimeToRun(nextJob)); | ||
|
|
||
| await queue.add( | ||
| nextJob.id, | ||
| { | ||
| ...nextJob.data, | ||
| concurrencyLimitHit: true, | ||
| }, | ||
| { | ||
| ...nextJob.opts, | ||
| jobId: nextJob.id, | ||
| priority: nextJob.priority, | ||
| }, | ||
| ); | ||
| } | ||
| runningJobs.add(job.id); | ||
| } | ||
| } | ||
|
|
||
| if (job.data && job.data.sentry && Sentry.isInitialized()) { | ||
| Sentry.continueTrace( | ||
| { | ||
| sentryTrace: job.data.sentry.trace, | ||
| baggage: job.data.sentry.baggage, | ||
| }, | ||
| () => { | ||
| Sentry.startSpan( | ||
| { | ||
| name: "Scrape job", | ||
| attributes: { | ||
| job: job.id, | ||
| worker: process.env.FLY_MACHINE_ID ?? worker.id, | ||
| }, | ||
| }, | ||
| async (span) => { | ||
| await Sentry.startSpan( | ||
| { | ||
| name: "Process scrape job", | ||
| op: "queue.process", | ||
| attributes: { | ||
| "messaging.message.id": job.id, | ||
| "messaging.destination.name": getScrapeQueue().name, | ||
| "messaging.message.body.size": job.data.sentry.size, | ||
| "messaging.message.receive.latency": | ||
| Date.now() - (job.processedOn ?? job.timestamp), | ||
| "messaging.message.retry.count": job.attemptsMade, | ||
| }, | ||
| }, | ||
| async () => { | ||
| let res; | ||
| try { | ||
| res = await processJobInternal(token, job); | ||
| } finally { | ||
| await afterJobDone(job); | ||
| } | ||
|
|
||
| if (res !== null) { | ||
| span.setStatus({ code: 2 }); // ERROR | ||
| } else { | ||
| span.setStatus({ code: 1 }); // OK | ||
| } | ||
| }, | ||
| ); | ||
| }, | ||
| ); | ||
| }, | ||
| ); | ||
| } else { | ||
| Sentry.startSpan( | ||
| { | ||
| name: "Scrape job", | ||
| name: "Process job", | ||
| attributes: { | ||
| job: job.id, | ||
| worker: process.env.FLY_MACHINE_ID ?? worker.id, | ||
| worker: process.env.FLY_MACHINE_ID ?? queue.name, | ||
| }, | ||
| }, | ||
| () => { | ||
| processJobInternal(token, job).finally(() => afterJobDone(job)); | ||
| processJobFn(token, job).finally(() => { | ||
| if (job.id) { | ||
| runningJobs.delete(job.id); | ||
| } | ||
| }); | ||
| }, | ||
| ); | ||
| } | ||
|
|
||
| await sleep(gotJobInterval); | ||
| } else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.