2020-12-15 16:09:41 +01:00
|
|
|
require('dotenv').config()
|
|
|
|
const cron = require('cron')
|
2021-02-18 18:46:48 +01:00
|
|
|
const { getEvents } = require('./events')
|
|
|
|
const { updateTree } = require('./update')
|
2021-01-17 22:47:07 +01:00
|
|
|
const { action } = require('./utils')
|
2020-12-15 16:09:41 +01:00
|
|
|
|
2021-02-18 18:46:48 +01:00
|
|
|
async function main() {
|
|
|
|
// todo retry
|
2021-01-17 22:47:07 +01:00
|
|
|
for (const type of Object.values(action)) {
|
2021-02-18 18:46:48 +01:00
|
|
|
const { committedEvents, pendingEvents } = await getEvents(type)
|
|
|
|
console.log(`There are ${pendingEvents.length} unprocessed ${type}s`)
|
|
|
|
await updateTree(committedEvents, pendingEvents, type)
|
2020-12-15 16:09:41 +01:00
|
|
|
}
|
|
|
|
console.log('Done')
|
|
|
|
}
|
|
|
|
|
|
|
|
cron.job(process.env.CRON_EXPRESSION, main, null, true, null, null, true)
|