Skip to content

Commit

Permalink
fix: dailySatSummary job depends on views-days
Browse files Browse the repository at this point in the history
  • Loading branch information
Soxasora committed Jan 7, 2025
1 parent 3a09439 commit 4a67890
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 18 deletions.
16 changes: 0 additions & 16 deletions prisma/migrations/20241223184742_satsummary_job/migration.sql

This file was deleted.

2 changes: 0 additions & 2 deletions worker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { ApolloClient, HttpLink, InMemoryCache } from '@apollo/client'
import { indexItem, indexAllItems } from './search'
import { timestampItem } from './ots'
import { computeStreaks, checkStreak } from './streak'
import { dailySatSummary } from './satSummary'
import { nip57 } from './nostr'
import fetch from 'cross-fetch'
import { authenticatedLndGrpc } from '@/lib/lnd'
Expand Down Expand Up @@ -132,7 +131,6 @@ async function work () {
await boss.work('earn', jobWrapper(earn))
await boss.work('streak', jobWrapper(computeStreaks))
await boss.work('checkStreak', jobWrapper(checkStreak))
await boss.work('dailySatSummary', jobWrapper(dailySatSummary))
await boss.work('nip57', jobWrapper(nip57))
await boss.work('views-*', jobWrapper(views))
await boss.work('rankViews', jobWrapper(rankViews))
Expand Down
3 changes: 3 additions & 0 deletions worker/satSummary.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { notifySatSummary } from '@/lib/webPush'
import { msatsToSats } from '@/lib/format'
export async function dailySatSummary ({ models }) {
console.log('running dailySatSummary')
try {
const stats = await models.$queryRaw`
SELECT
Expand All @@ -26,5 +27,7 @@ export async function dailySatSummary ({ models }) {
}
} catch (err) {
console.error('failed to process daily sat summary', err)
} finally {
console.log('finished dailySatSummary')
}
}
2 changes: 2 additions & 0 deletions worker/views.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import createPrisma from '@/lib/create-prisma'
import { dailySatSummary } from './satSummary'

const viewPrefixes = ['reg_growth', 'spender_growth', 'item_growth', 'spending_growth',
'stackers_growth', 'stacking_growth', 'user_stats', 'sub_stats']
Expand All @@ -22,6 +23,7 @@ export async function views ({ data: { period } = { period: 'days' } }) {
await models.$queryRawUnsafe(`REFRESH MATERIALIZED VIEW CONCURRENTLY ${view}_${period}`)
}
} finally {
if (period === 'days') await dailySatSummary({ models }).catch(console.error) // run dailySatSummary after views-days refresh
await models.$disconnect()
}
}
Expand Down

0 comments on commit 4a67890

Please sign in to comment.