Skip to content

Commit 0de5060

Browse files
chedieckFabcien
authored andcommitted
fix: current prices after initial sync
1 parent 1a18e66 commit 0de5060

2 files changed

Lines changed: 17 additions & 15 deletions

File tree

jobs/initJobs.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,7 @@ const main = async (): Promise<void> => {
1616
await blockchainQueue.obliterate({ force: true })
1717
await cleanupQueue.obliterate({ force: true })
1818

19-
await pricesQueue.add('syncCurrentPrices',
20-
{},
21-
{
22-
jobId: 'syncCurrentPrices',
23-
removeOnFail: false,
24-
repeat: {
25-
every: CURRENT_PRICE_REPEAT_DELAY
26-
}
27-
}
28-
)
29-
30-
await syncCurrentPricesWorker(pricesQueue.name)
31-
19+
// Start blockchain sync first; current prices job starts only after it completes
3220
await blockchainQueue.add('syncBlockchainAndPrices',
3321
{},
3422
{
@@ -37,7 +25,20 @@ const main = async (): Promise<void> => {
3725
removeOnFail: true
3826
}
3927
)
40-
await syncBlockchainAndPricesWorker(blockchainQueue.name)
28+
void await syncBlockchainAndPricesWorker(blockchainQueue.name, async () => {
29+
await pricesQueue.add('syncCurrentPrices',
30+
{},
31+
{
32+
jobId: 'syncCurrentPrices',
33+
removeOnFail: false,
34+
repeat: {
35+
every: CURRENT_PRICE_REPEAT_DELAY
36+
}
37+
}
38+
)
39+
await syncCurrentPricesWorker(pricesQueue.name)
40+
console.log('Current prices sync job started after blockchain sync completion.')
41+
})
4142

4243
await cleanupQueue.add(
4344
'cleanupClientPayments',

jobs/workers.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export const syncCurrentPricesWorker = async (queueName: string): Promise<void>
3131
})
3232
}
3333

34-
export const syncBlockchainAndPricesWorker = async (queueName: string): Promise<void> => {
34+
export const syncBlockchainAndPricesWorker = async (queueName: string, onComplete?: () => Promise<void> | void): Promise<void> => {
3535
const worker = new Worker(
3636
queueName,
3737
async (job) => {
@@ -53,6 +53,7 @@ export const syncBlockchainAndPricesWorker = async (queueName: string): Promise<
5353
await multiBlockchainClient.destroy()
5454
console.log('Done.')
5555
console.log(`job ${job.id as string}: blockchain + prices sync finished`)
56+
await onComplete?.()
5657
})()
5758
})
5859

0 commit comments

Comments
 (0)