-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathworker.js
44 lines (35 loc) · 1.57 KB
/
worker.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
#!/usr/bin/env node
import 'dotenv/config.js' // eslint-disable-line import/no-unassigned-import
import ms from 'ms'
import apiConsumer from './lib/api/consumers/api-consumer.js'
import exportToExploitationDBConsumer from './lib/api/consumers/export-to-exploitation-db-consumer.js'
import cleanJobStatusConsumer from './lib/api/consumers/clean-job-status-consumer.js'
import mongo from './lib/util/mongo.cjs'
import queue from './lib/util/queue.cjs'
import composeCommune from './lib/jobs/compose-commune.cjs'
import computeBanStats from './lib/jobs/compute-ban-stats.cjs'
import balGarbageCollector from './lib/compose/bal-garbage-collector/index.js'
import {init} from './lib/util/sequelize.js'
async function main() {
// Mongo DB : connecting and creating indexes
await mongo.connect()
// Postgres DB : Testing connection and syncing models
await init()
if (process.env.NODE_ENV === 'production') {
// Garbage collector
await balGarbageCollector()
}
// Legacy
queue('compose-commune').process(4, composeCommune)
queue('compute-ban-stats').process(1, computeBanStats)
queue('compute-ban-stats').add({}, {jobId: 'computeBanStatsJobId', repeat: {every: ms('15m')}, removeOnComplete: true})
// BanID
queue('api').process(1, apiConsumer)
queue('export-to-exploitation-db').process(1, exportToExploitationDBConsumer)
queue('clean-job-status').process(1, cleanJobStatusConsumer)
queue('clean-job-status').add({}, {jobId: 'cleanJobStatusJobId', repeat: {every: ms('1d')}, removeOnComplete: true})
}
main().catch(error => {
console.error(error)
process.exit(1)
})