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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove any already-waiting jobs to avoid duplicates
|
// Skip hashtags already in-flight (waiting or active) to avoid pile-up
|
||||||
const waiting = await priceUpdateQueue.getJobs(['waiting', 'delayed'])
|
const inFlight = await priceUpdateQueue.getJobs(['waiting', 'active', 'delayed'])
|
||||||
const waitingIds = new Set(waiting.map((j) => j.data?.hashtagId))
|
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) {
|
for (const hashtag of toQueue) {
|
||||||
await priceUpdateQueue.add(
|
await priceUpdateQueue.add(
|
||||||
'update-price',
|
'update-price',
|
||||||
{ hashtagId: hashtag.id, tag: hashtag.tag },
|
{ hashtagId: hashtag.id, tag: hashtag.tag },
|
||||||
{
|
{
|
||||||
jobId: `price-${hashtag.id}`, // deduplicates against waiting/active (hash persists)
|
// No static jobId — avoids silent dedup drops from stale Redis hashes.
|
||||||
removeOnComplete: true, // remove hash on completion so jobId can be reused next sweep
|
// In-flight dedup is handled by the inFlightIds check above.
|
||||||
|
removeOnComplete: true,
|
||||||
removeOnFail: { count: 50 },
|
removeOnFail: { count: 50 },
|
||||||
attempts: 3,
|
attempts: 3,
|
||||||
backoff: { type: 'exponential', delay: 5000 },
|
backoff: { type: 'exponential', delay: 5000 },
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user