stacker.news/worker/index.js

53 lines
1.5 KiB
JavaScript
Raw Normal View History

2022-01-05 14:37:34 -06:00
const PgBoss = require('pg-boss')
const dotenv = require('dotenv')
dotenv.config({ path: '..' })
2022-01-17 11:41:17 -06:00
const { PrismaClient } = require('@prisma/client')
const { checkInvoice, checkWithdrawal } = require('./wallet')
const { repin } = require('./repin')
const { trust } = require('./trust')
2022-02-25 11:34:09 -06:00
const { auction } = require('./auction')
2022-07-07 14:14:22 -05:00
const { earn } = require('./earn')
2022-01-25 13:34:51 -06:00
const { ApolloClient, HttpLink, InMemoryCache } = require('@apollo/client')
const { indexItem, indexAllItems } = require('./search')
const fetch = require('cross-fetch')
2022-01-05 14:37:34 -06:00
async function work () {
2022-01-17 11:41:17 -06:00
const boss = new PgBoss(process.env.DATABASE_URL)
const models = new PrismaClient()
2022-01-25 13:34:51 -06:00
const apollo = new ApolloClient({
link: new HttpLink({
uri: `${process.env.SELF_URL}/api/graphql`,
fetch
}),
cache: new InMemoryCache(),
defaultOptions: {
watchQuery: {
fetchPolicy: 'network-only',
nextFetchPolicy: 'network-only'
},
query: {
fetchPolicy: 'network-only',
nextFetchPolicy: 'network-only'
}
}
})
const args = { boss, models, apollo }
2022-01-14 11:28:05 -06:00
2022-01-17 11:41:17 -06:00
boss.on('error', error => console.error(error))
2022-01-07 10:32:31 -06:00
2022-01-17 11:41:17 -06:00
await boss.start()
await boss.work('checkInvoice', checkInvoice(args))
await boss.work('checkWithdrawal', checkWithdrawal(args))
await boss.work('repin-*', repin(args))
await boss.work('trust', trust(args))
2022-01-25 13:34:51 -06:00
await boss.work('indexItem', indexItem(args))
await boss.work('indexAllItems', indexAllItems(args))
2022-02-25 11:34:09 -06:00
await boss.work('auction', auction(args))
2022-03-17 15:13:19 -05:00
await boss.work('earn', earn(args))
2022-01-05 14:37:34 -06:00
2022-01-17 11:41:17 -06:00
console.log('working jobs')
2022-01-05 14:37:34 -06:00
}
work()