Skip to content

Commit e0b3af1

Browse files
ypoplavspovilasv
authored andcommitted
feat: add more logging for cronjobs (#6940)
* add more logging for cronjobs
1 parent 1bd0911 commit e0b3af1

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ build-all-platforms: ## Build binaries for all supported platforms
313313
.PHONY: run-api
314314
run-api: ## Run API server locally
315315
@echo "Starting API server..."
316-
$(GO) run -ldflags='$(LD_FLAGS_API)' cmd/api-server/main.go
316+
$(GO) run -ldflags='$(LD_FLAGS_API)' ./cmd/api-server/
317317

318318
.PHONY: run-api-race
319319
run-api-race: ## Run API server with race detector

internal/cronjob/robfig/manager.go

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package robfig
55
import (
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.
4344
func (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.
4851
func (m Manager) Stop() {
52+
m.logger.Infow("cron manager stopping")
4953
m.cron.Stop()
54+
m.logger.Infow("cron manager stopped")
5055
}
5156

5257
func cronSpec(config testkube.TestWorkflowCronJobConfig) string {
@@ -58,12 +63,15 @@ func cronSpec(config testkube.TestWorkflowCronJobConfig) string {
5863
}
5964

6065
func (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

Comments
 (0)