From 7552f19fcbf81ba9a2eab61fee0be5f4ad8b459a Mon Sep 17 00:00:00 2001 From: Filipe Pina Date: Sun, 11 Feb 2024 01:45:19 +0000 Subject: [PATCH] replace magic `H` with `~` --- dkron/job.go | 8 ++++---- dkron/job_test.go | 8 ++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/dkron/job.go b/dkron/job.go index e9aaf8dfc..2de8bf068 100644 --- a/dkron/job.go +++ b/dkron/job.go @@ -306,17 +306,17 @@ func (j *Job) GetTimeLocation() *time.Location { } // scheduleHash replaces H in the cron spec by a value derived from job Name -// such as "0 0 H * * *" +// such as "0 0 ~ * * *" func (j *Job) scheduleHash() string { spec := j.Schedule - if strings.Contains(spec, "H") && strings.Count(strings.TrimSpace(spec), " ") == 5 { + if strings.Contains(spec, "~") && strings.Count(strings.TrimSpace(spec), " ") == 5 { hash := 0 for _, c := range j.Name { hash += int(c) } parts := strings.Split(spec, " ") for index, part := range parts { - if strings.Contains(part, "H") { + if strings.Contains(part, "~") { // mods taken in accordance with https://dkron.io/docs/usage/cron-spec/#cron-expression-format partHash := hash switch index { @@ -331,7 +331,7 @@ func (j *Job) scheduleHash() string { default: partHash %= 60 } - parts[index] = strings.ReplaceAll(part, "H", strconv.Itoa(partHash)) + parts[index] = strings.ReplaceAll(part, "~", strconv.Itoa(partHash)) } } return strings.Join(parts, " ") diff --git a/dkron/job_test.go b/dkron/job_test.go index 22dc1746f..74179e8d1 100644 --- a/dkron/job_test.go +++ b/dkron/job_test.go @@ -192,6 +192,14 @@ func Test_isRunnable(t *testing.T) { } } +func Test_scheduleHash(t *testing.T) { + job := &Job{ + Name: "test_job", + Schedule: "0 0 ~ * * *", + } + assert.Equal(t, "0 0 18 * * *", job.scheduleHash()) +} + type gRPCClientMock struct { }