mirror of
https://github.com/simstudioai/sim.git
synced 2026-09-24 15:45:35 +08:00
feat(starter): added workflow_schedule table and helper to convert date to cron expression
This commit is contained in:
@@ -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')
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user