Files
nyaa-crawler/src/server/services/cron-util.ts
T
Jason Stedwell 14ce08c3c2
Build and Push Docker Image / build (push) Failing after 1s
version 2 build
2026-06-28 21:47:04 -05:00

15 lines
587 B
TypeScript

/**
* 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} * * *`
}