This repository has been archived by the owner on Sep 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap.js
64 lines (50 loc) · 1.88 KB
/
bootstrap.js
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
// Copyright (c) 2018-2020, BB Jansen
//
// Please see the included LICENSE file for more information.
'use strict'
// Setup scheduler
const scheduler = require('node-cron');
// Setup logger
require('console-stamp')(console, {
pattern: 'dd/mm/yyyy HH:MM:ss.l',
colors: {
stamp: 'green',
label: 'white',
}
})
// Setup database tables
require('./utils/db/schema');
// Initialize
(async () => {
try {
// Let's create a bunch of queues shall we?
const keyBlock = await require('./libs/rabbitmq')('keyBlock')
const microBlock = await require('./libs/rabbitmq')('microBlock')
const verifyBlock = await require('./libs/rabbitmq')('verifyBlock')
const processAddress = await require('./libs/rabbitmq')('processAddress')
// Setup delayed message support for the `verifyBlock` queue.
verifyBlock.assertExchange('delayed', 'x-delayed-message', {
autoDelete: false,
durable: true,
passive: true,
arguments: { 'x-delayed-type': 'direct' }
})
// Bind `verifyBlock` queue to 'delayed' exchange via a route named 'block'.
verifyBlock.bindQueue('verifyBlock', 'delayed', 'block')
// Schedule a job that will loop on a specified interval set with COLLECTOR_INTERVAL
// COLLECTOR_INTERVAL is defined in ms so lets convert it to seconds.
const Collector = scheduler.schedule('*/' + (+process.env.COLLECTOR_INTERVAL / 1000) + ' * * * * *', () => {
require('./scripts/collect')(keyBlock)
})
// Are you ready? Produce!
Collector.start()
// Yes! Consume!
require('./workers/block/key')(keyBlock, microBlock)
require('./workers/block/micro')(microBlock, verifyBlock, processAddress)
require('./workers/block/verify')(verifyBlock, Collector, keyBlock, microBlock, processAddress)
require('./workers/address/process')(processAddress)
}
catch(err) {
console.error(err.toString())
}
})()