Files
nyaa-crawler/src/server/services/cron-util.ts
T

15 lines
587 B
TypeScript
Raw Normal View History

2026-06-28 21:47:04 -05:00
/**
* Convert a polling interval in seconds into a cron expression.
* Pure and side-effect free so it can be unit-tested without touching the DB.
* - < 60s → every minute ("* * * * *")
* - < 60 minutes → every N minutes ("*\/15 * * * *")
* - otherwise → every N hours ("0 *\/6 * * *")
*/
export function secondsToCron(seconds: number): string {
if (seconds < 60) return '* * * * *'
const minutes = Math.round(seconds / 60)
if (minutes < 60) return `*/${minutes} * * * *`
const hours = Math.round(minutes / 60)
return `0 */${hours} * * *`
}