added cron support

This commit is contained in:
yashsinghcodes
2025-07-14 20:33:50 +05:30
parent ff4a63daea
commit b2dfe8d8f9
3 changed files with 54 additions and 20 deletions
+17 -6
View File
@@ -4034,6 +4034,7 @@ func runInitEs(ctx context.Context) {
// FIXME: This should ONLY run on one backend instance
schedules, err := shuffle.GetAllSchedules(ctx, "ALL")
log.Printf("Schedules %s", schedules)
if err != nil {
log.Printf("[WARNING] Failed getting schedules during service init: %s", err)
} else {
@@ -4078,14 +4079,23 @@ func runInitEs(ctx context.Context) {
//log.Printf("Schedule: %#v", schedule)
//log.Printf("Schedule time: every %d seconds", schedule.Seconds)
jobret, err := newscheduler.Every(schedule.Seconds).Seconds().NotImmediately().Run(job(schedule))
if err != nil {
log.Printf("[ERROR] Failed to start schedule for workflow %s: %s", schedule.WorkflowId, err)
if schedule.Seconds == 0 && len(schedule.Frequency) > 0 {
cronJob, err := CronScheduler.Cron(schedule.Frequency).Do(job(schedule))
if err != nil {
log.Printf("[ERROR] Failed to start schedule for workflow %s: %s", schedule.WorkflowId, err)
} else {
log.Printf("[DEBUG] Successfully started schedule for workflow %s", schedule.WorkflowId)
}
cronJobs[schedule.Id] = cronJob
} else {
log.Printf("[DEBUG] Successfully started schedule for workflow %s", schedule.WorkflowId)
jobret, err := newscheduler.Every(schedule.Seconds).Seconds().NotImmediately().Run(job(schedule))
if err != nil {
log.Printf("[ERROR] Failed to start schedule for workflow %s: %s", schedule.WorkflowId, err)
} else {
log.Printf("[DEBUG] Successfully started schedule for workflow %s", schedule.WorkflowId)
}
scheduledJobs[schedule.Id] = jobret
}
scheduledJobs[schedule.Id] = jobret
}
}
@@ -5090,6 +5100,7 @@ func handleAppZipUpload(resp http.ResponseWriter, request *http.Request) {
func initHandlers() {
var err error
ctx := context.Background()
CronScheduler.StartAsync()
log.Printf("[DEBUG] Starting Shuffle backend - initializing database connection")
//requestCache = cache.New(5*time.Minute, 10*time.Minute)