stacker.news/worker/index.js

68 lines
2.1 KiB
JavaScript
Raw Normal View History

2022-01-05 20:37:34 +00:00
const PgBoss = require('pg-boss')
const dotenv = require('dotenv')
dotenv.config({ path: '..' })
2022-01-17 17:41:17 +00:00
const { PrismaClient } = require('@prisma/client')
const { checkInvoice, checkWithdrawal } = require('./wallet')
const { repin } = require('./repin')
const { trust } = require('./trust')
2022-02-25 17:34:09 +00:00
const { auction } = require('./auction')
2022-07-07 19:14:22 +00:00
const { earn } = require('./earn')
2022-01-25 19:34:51 +00:00
const { ApolloClient, HttpLink, InMemoryCache } = require('@apollo/client')
const { indexItem, indexAllItems } = require('./search')
2023-01-22 20:17:50 +00:00
const { timestampItem } = require('./ots')
2023-02-02 19:47:09 +00:00
const { computeStreaks, checkStreak } = require('./streak')
2023-02-14 22:58:12 +00:00
const { nip57 } = require('./nostr')
2022-01-25 19:34:51 +00:00
const fetch = require('cross-fetch')
2023-02-14 22:58:12 +00:00
const { authenticatedLndGrpc } = require('ln-service')
2022-01-05 20:37:34 +00:00
async function work () {
2022-01-17 17:41:17 +00:00
const boss = new PgBoss(process.env.DATABASE_URL)
const models = new PrismaClient()
2022-01-25 19:34:51 +00:00
const apollo = new ApolloClient({
link: new HttpLink({
uri: `${process.env.SELF_URL}/api/graphql`,
fetch
}),
cache: new InMemoryCache(),
defaultOptions: {
watchQuery: {
2022-11-24 19:22:58 +00:00
fetchPolicy: 'no-cache',
nextFetchPolicy: 'no-cache'
2022-01-25 19:34:51 +00:00
},
query: {
2022-11-24 19:22:58 +00:00
fetchPolicy: 'no-cache',
nextFetchPolicy: 'no-cache'
2022-01-25 19:34:51 +00:00
}
}
})
2023-02-14 22:58:12 +00:00
const { lnd } = authenticatedLndGrpc({
cert: process.env.LND_CERT,
macaroon: process.env.LND_MACAROON,
socket: process.env.LND_SOCKET
})
const args = { boss, models, apollo, lnd }
2022-01-14 17:28:05 +00:00
2022-01-17 17:41:17 +00:00
boss.on('error', error => console.error(error))
2022-01-07 16:32:31 +00:00
2022-01-17 17:41:17 +00: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))
2023-01-22 20:17:50 +00:00
await boss.work('timestampItem', timestampItem(args))
2022-01-25 19:34:51 +00:00
await boss.work('indexItem', indexItem(args))
await boss.work('indexAllItems', indexAllItems(args))
2022-02-25 17:34:09 +00:00
await boss.work('auction', auction(args))
2022-03-17 20:13:19 +00:00
await boss.work('earn', earn(args))
2023-02-01 14:44:35 +00:00
await boss.work('streak', computeStreaks(args))
2023-02-02 19:47:09 +00:00
await boss.work('checkStreak', checkStreak(args))
2023-02-14 22:58:12 +00:00
await boss.work('nip57', nip57(args))
2022-01-05 20:37:34 +00:00
2022-01-17 17:41:17 +00:00
console.log('working jobs')
2022-01-05 20:37:34 +00:00
}
work()