-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathinitJobs.ts
More file actions
75 lines (64 loc) · 2.13 KB
/
initJobs.ts
File metadata and controls
75 lines (64 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { CLIENT_PAYMENT_EXPIRATION_TIME, CURRENT_PRICE_REPEAT_DELAY, UNCONFIRMED_TX_CHECK_INTERVAL } from 'constants/index'
import { Queue } from 'bullmq'
import { redisBullMQ } from 'redis/clientInstance'
import EventEmitter from 'events'
import { syncCurrentPricesWorker, syncBlockchainAndPricesWorker, cleanupClientPaymentsWorker, verifyUnconfirmedTransactionsWorker } from './workers'
EventEmitter.defaultMaxListeners = 20
const main = async (): Promise<void> => {
// --- force fresh start ---
const pricesQueue = new Queue('pricesSync', { connection: redisBullMQ })
const blockchainQueue = new Queue('blockchainSync', { connection: redisBullMQ })
const cleanupQueue = new Queue('clientPaymentCleanup', { connection: redisBullMQ })
const unconfirmedTxQueue = new Queue('unconfirmedTxVerification', { connection: redisBullMQ })
await pricesQueue.obliterate({ force: true })
await blockchainQueue.obliterate({ force: true })
await cleanupQueue.obliterate({ force: true })
await unconfirmedTxQueue.obliterate({ force: true })
await pricesQueue.add('syncCurrentPrices',
{},
{
jobId: 'syncCurrentPrices',
removeOnFail: false,
repeat: {
every: CURRENT_PRICE_REPEAT_DELAY
}
}
)
await syncCurrentPricesWorker(pricesQueue.name)
await blockchainQueue.add('syncBlockchainAndPrices',
{},
{
jobId: 'syncBlockchainAndPrices',
removeOnComplete: true,
removeOnFail: true
}
)
await syncBlockchainAndPricesWorker(blockchainQueue.name)
await cleanupQueue.add(
'cleanupClientPayments',
{},
{
jobId: 'cleanupClientPayments',
removeOnComplete: true,
removeOnFail: true,
repeat: {
every: CLIENT_PAYMENT_EXPIRATION_TIME
}
}
)
await cleanupClientPaymentsWorker(cleanupQueue.name)
await unconfirmedTxQueue.add(
'verifyUnconfirmedTransactions',
{},
{
jobId: 'verifyUnconfirmedTransactions',
removeOnComplete: true,
removeOnFail: true,
repeat: {
every: UNCONFIRMED_TX_CHECK_INTERVAL
}
}
)
await verifyUnconfirmedTransactionsWorker(unconfirmedTxQueue.name)
}
void main()