Files
logbuch/scripts/cron.mjs
T
Matthias G 65346d0c09 Send a weekly digest to Slack
POST /api/v1/weekly-report collects everything published in the last seven
days, groups it by project and posts one message. dry=1 returns the message
instead of sending it, no publications means no message, a missing webhook
answers 501 instead of failing quietly. scripts/cron.mjs runs the due
publishing first, then the digest.
2026-08-03 11:39:54 +02:00

35 lines
787 B
JavaScript

const base = process.env.CRON_BASE ?? `http://127.0.0.1:${process.env.PORT ?? 4700}`
const secret = process.env.CRON_SECRET?.trim()
if (!secret) {
console.error('[cron] CRON_SECRET fehlt')
process.exit(1)
}
const tasks = process.argv.slice(2)
const paths = tasks.length > 0 ? tasks : ['/api/v1/publish-due', '/api/v1/weekly-report']
let failed = false
for (const path of paths) {
try {
const response = await fetch(`${base}${path}`, {
method: 'POST',
headers: { authorization: `Bearer ${secret}` },
})
const body = await response.text()
console.log(`[cron] ${path} ${response.status} ${body}`)
if (!response.ok) {
failed = true
}
} catch (error) {
console.error(`[cron] ${path} fehlgeschlagen`, error)
failed = true
}
}
process.exit(failed ? 1 : 0)