@@ -5,6 +5,7 @@ package robfig
55import (
66 "context"
77 "fmt"
8+ "time"
89
910 "github.com/robfig/cron/v3"
1011 "go.uber.org/zap"
@@ -41,12 +42,16 @@ func New(logger *zap.SugaredLogger, executor Executor, proModeEnabled bool) Mana
4142
4243// Start the cron manager in its own goroutine, or no-op if already started.
4344func (m Manager ) Start () {
45+ m .logger .Infow ("cron manager starting" )
4446 m .cron .Start ()
47+ m .logger .Infow ("cron manager started" )
4548}
4649
4750// Stop stops the cron manager if it is running; otherwise it does nothing.
4851func (m Manager ) Stop () {
52+ m .logger .Infow ("cron manager stopping" )
4953 m .cron .Stop ()
54+ m .logger .Infow ("cron manager stopped" )
5055}
5156
5257func cronSpec (config testkube.TestWorkflowCronJobConfig ) string {
@@ -58,12 +63,15 @@ func cronSpec(config testkube.TestWorkflowCronJobConfig) string {
5863}
5964
6065func (m Manager ) ReplaceWorkflowSchedules (ctx context.Context , workflow cronjob.Workflow , configs []testkube.TestWorkflowCronJobConfig ) error {
66+ log := m .logger .With ("workflow" , workflow .Name )
6167 // Delete all existing schedules for this workflow.
6268 // This is because we may not know when a schedule is removed from
6369 // an object so we must recreate the entire schedule from scratch
6470 // each time there is a change.
6571 if _ , exists := m .cronEntries [workflow .Name ]; exists {
72+ log .Infow ("removing existing schedules" , "existing_entries" , m .cronEntries [workflow .Name ])
6673 for _ , entryId := range m .cronEntries [workflow .Name ] {
74+ log .Debugw ("removing schedule entry" , "entry_id" , entryId )
6775 m .cron .Remove (entryId )
6876 }
6977 delete (m .cronEntries , workflow .Name )
@@ -72,6 +80,19 @@ func (m Manager) ReplaceWorkflowSchedules(ctx context.Context, workflow cronjob.
7280
7381 for _ , config := range configs {
7482 spec := cronSpec (config )
83+
84+ if config .Timezone != nil {
85+ log .Infow ("adding schedule" ,
86+ "spec" , spec ,
87+ "cron" , config .Cron ,
88+ "timezone" , config .Timezone .Value ,
89+ )
90+ } else {
91+ log .Infow ("adding schedule" ,
92+ "spec" , spec ,
93+ "cron" , config .Cron ,
94+ )
95+ }
7596 entryId , err := m .cron .AddJob (spec , m .testWorkflowExecuteJob (ctx , workflow .Name , spec , config ))
7697 if err != nil {
7798 m .logger .Errorw ("Error adding cron for workflow, continuing processing" ,
@@ -81,8 +102,16 @@ func (m Manager) ReplaceWorkflowSchedules(ctx context.Context, workflow cronjob.
81102 continue
82103 }
83104 m.cronEntries [workflow.Name ][spec ] = entryId
84- }
105+ entry := m . cron . Entry ( entryId )
85106
107+ log .Infow ("schedule registered" ,
108+ "entry_id" , entryId ,
109+ "spec" , spec ,
110+ "next_run" , entry .Next .Format (time .RFC3339 ),
111+ "prev_run" , entry .Prev .Format (time .RFC3339 ),
112+ )
113+ }
114+ log .Infow ("ReplaceWorkflowSchedules finished" )
86115 return nil
87116}
88117
0 commit comments