stacker.news/worker/index.js

70 lines
2.2 KiB
JavaScript
Raw Normal View History

2022-01-05 14:37:34 -06:00
const PgBoss = require('pg-boss')
require('@next/env').loadEnvConfig('..')
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')
2023-01-22 14:17:50 -06:00
const { timestampItem } = require('./ots')
2023-02-02 13:47:09 -06:00
const { computeStreaks, checkStreak } = require('./streak')
2023-02-14 16:58:12 -06:00
const { nip57 } = require('./nostr')
2022-01-25 13:34:51 -06:00
const fetch = require('cross-fetch')
2023-02-14 16:58:12 -06:00
const { authenticatedLndGrpc } = require('ln-service')
2023-05-23 09:21:04 -05:00
const { views, rankViews } = require('./views')
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: {
2022-11-24 13:22:58 -06:00
fetchPolicy: 'no-cache',
nextFetchPolicy: 'no-cache'
2022-01-25 13:34:51 -06:00
},
query: {
2022-11-24 13:22:58 -06:00
fetchPolicy: 'no-cache',
nextFetchPolicy: 'no-cache'
2022-01-25 13:34:51 -06:00
}
}
})
2023-02-14 16:58:12 -06: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 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))
2023-01-22 14:17:50 -06:00
await boss.work('timestampItem', timestampItem(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))
2023-02-01 08:44:35 -06:00
await boss.work('streak', computeStreaks(args))
2023-02-02 13:47:09 -06:00
await boss.work('checkStreak', checkStreak(args))
2023-02-14 16:58:12 -06:00
await boss.work('nip57', nip57(args))
2023-05-18 18:41:56 -05:00
await boss.work('views', views(args))
2023-05-23 09:21:04 -05:00
await boss.work('rankViews', rankViews(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()