watch, dont poll
This commit is contained in:
parent
054c73b926
commit
8347177c77
|
|
@ -9,7 +9,7 @@ import { SCHEDULES, type CronJob } from './lib/schedules'
|
|||
import type { Child } from 'hono/jsx'
|
||||
import { join } from 'path'
|
||||
import { mkdir, writeFile } from 'fs/promises'
|
||||
import { existsSync } from 'fs'
|
||||
import { existsSync, watch } from 'fs'
|
||||
|
||||
const APPS_DIR = process.env.APPS_DIR!
|
||||
|
||||
|
|
@ -372,8 +372,10 @@ async function init() {
|
|||
}
|
||||
}
|
||||
|
||||
// Re-discover every 60s
|
||||
setInterval(async () => {
|
||||
// Watch for cron file changes
|
||||
let debounceTimer: Timer | null = null
|
||||
|
||||
async function rediscover() {
|
||||
const jobs = await discoverCronJobs()
|
||||
const existing = getAllJobs()
|
||||
|
||||
|
|
@ -403,7 +405,15 @@ setInterval(async () => {
|
|||
}
|
||||
|
||||
setJobs(jobs)
|
||||
}, 60000)
|
||||
}
|
||||
|
||||
watch(APPS_DIR, { recursive: true }, (_event, filename) => {
|
||||
if (!filename?.includes('/cron/') && !filename?.includes('\\cron\\')) return
|
||||
if (!filename.endsWith('.ts')) return
|
||||
|
||||
if (debounceTimer) clearTimeout(debounceTimer)
|
||||
debounceTimer = setTimeout(rediscover, 100)
|
||||
})
|
||||
|
||||
init()
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user