feat(starter): added workflow_schedule table and helper to convert date to cron expression

This commit is contained in:
Waleed Latif
2025-02-18 20:13:02 -08:00
parent 4c7630d72e
commit 4c9b0e9e2c
5 changed files with 754 additions and 0 deletions
+34
View File
@@ -23,3 +23,37 @@ export async function hashSecret(
.digest('hex')
return { hash, salt: useSalt }
}
export function convertScheduleOptionsToCron(
scheduleType: string,
options: Record<string, string>
): string {
switch (scheduleType) {
case 'minutes': {
const interval = options.minutesInterval || '15'
// For example, if options.minutesStartingAt is provided, use that as the start minute.
return `*/${interval} * * * *`
}
case 'hourly': {
// When scheduling hourly, take the specified minute offset
return `${options.hourlyMinute || '00'} * * * *`
}
case 'daily': {
// Expected dailyTime in HH:MM
const [minute, hour] = (options.dailyTime || '00:09').split(':')
return `${minute || '00'} ${hour || '09'} * * *`
}
case 'monthly': {
// Expected monthlyDay and monthlyTime in HH:MM
const day = options.monthlyDay || '1'
const [minute, hour] = (options.monthlyTime || '00:09').split(':')
return `${minute || '00'} ${hour || '09'} ${day} * *`
}
case 'custom': {
// Use the provided cron expression directly
return options.cronExpression
}
default:
throw new Error('Unsupported schedule type')
}
}