Refactor code structure for improved readability and maintainability
Build Images and Deploy / Update-PROD-Stack (push) Successful in 1m19s
Build Images and Deploy / Update-PROD-Stack (push) Successful in 1m19s
This commit is contained in:
+7
-6
@@ -209,19 +209,20 @@ const schedulerWorker = new Worker(
|
||||
return
|
||||
}
|
||||
|
||||
// Remove any already-waiting jobs to avoid duplicates
|
||||
const waiting = await priceUpdateQueue.getJobs(['waiting', 'delayed'])
|
||||
const waitingIds = new Set(waiting.map((j) => j.data?.hashtagId))
|
||||
// Skip hashtags already in-flight (waiting or active) to avoid pile-up
|
||||
const inFlight = await priceUpdateQueue.getJobs(['waiting', 'active', 'delayed'])
|
||||
const inFlightIds = new Set(inFlight.map((j) => j.data?.hashtagId))
|
||||
|
||||
const toQueue = hashtags.filter((h) => !waitingIds.has(h.id))
|
||||
const toQueue = hashtags.filter((h) => !inFlightIds.has(h.id))
|
||||
|
||||
for (const hashtag of toQueue) {
|
||||
await priceUpdateQueue.add(
|
||||
'update-price',
|
||||
{ hashtagId: hashtag.id, tag: hashtag.tag },
|
||||
{
|
||||
jobId: `price-${hashtag.id}`, // deduplicates against waiting/active (hash persists)
|
||||
removeOnComplete: true, // remove hash on completion so jobId can be reused next sweep
|
||||
// No static jobId — avoids silent dedup drops from stale Redis hashes.
|
||||
// In-flight dedup is handled by the inFlightIds check above.
|
||||
removeOnComplete: true,
|
||||
removeOnFail: { count: 50 },
|
||||
attempts: 3,
|
||||
backoff: { type: 'exponential', delay: 5000 },
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user