feat(slack): add background job to detect Slack workspace joins
This commit is contained in:
parent
3797ff7925
commit
327f504df9
3 changed files with 239 additions and 0 deletions
29
server/plugins/check-slack-joins.js
Normal file
29
server/plugins/check-slack-joins.js
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
// server/plugins/check-slack-joins.js
|
||||
import { checkSlackJoins } from '../utils/checkSlackJoins.js'
|
||||
|
||||
const INTERVAL_MS = 3600000 // 1 hour
|
||||
|
||||
export default defineNitroPlugin(() => {
|
||||
// Don't run in test environment
|
||||
if (process.env.NODE_ENV === 'test') return
|
||||
|
||||
const config = useRuntimeConfig()
|
||||
const token = config.slackBotToken
|
||||
|
||||
if (!token) {
|
||||
console.warn('[check-slack-joins] No Slack bot token configured, skipping background job')
|
||||
return
|
||||
}
|
||||
|
||||
async function run() {
|
||||
try {
|
||||
await checkSlackJoins(token)
|
||||
} catch (err) {
|
||||
console.error('[check-slack-joins] Unhandled error:', err.message || err)
|
||||
}
|
||||
}
|
||||
|
||||
// Run immediately on server start, then every hour
|
||||
run()
|
||||
setInterval(run, INTERVAL_MS)
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue