Skip to content

Commit

Permalink
worker job to clear out unused lnurlp requests after 30 minutes
Browse files Browse the repository at this point in the history
  • Loading branch information
SatsAllDay committed Sep 28, 2023
1 parent 1e88066 commit 676094a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions worker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { indexItem, indexAllItems } from './search.js'
import { timestampItem } from './ots.js'
import { computeStreaks, checkStreak } from './streak.js'
import { nip57 } from './nostr.js'
import { lnurlpExpire } from './lnurlp-expire.js'

import fetch from 'cross-fetch'
import { authenticatedLndGrpc } from 'ln-service'
Expand Down Expand Up @@ -69,6 +70,9 @@ async function work () {
await boss.work('views', views(args))
await boss.work('rankViews', rankViews(args))

// Not a pg-boss job, but still a process to execute on an interval
lnurlpExpire({ models })

console.log('working jobs')
}

Expand Down
19 changes: 19 additions & 0 deletions worker/lnurlp-expire.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { datePivot } from '../lib/time.js'

export function lnurlpExpire ({ models }) {
setInterval(async () => {
try {
const { count } = await models.lnUrlpRequest.deleteMany({
where: {
createdAt: {
// clear out any requests that are older than 30 minutes
lt: datePivot(new Date(), { minutes: -30 })
}
}
})
console.log(`deleted ${count} lnurlp requests`)
} catch (err) {
console.error('error occurred deleting lnurlp requests', err)
}
}, 1000 * 60) // execute once per minute
}

0 comments on commit 676094a

Please sign in to comment.