Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schedule: support Second precision as adverted #65

Merged
merged 2 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions internal/engine/retry/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ func (r *Retry) Get(ctx context.Context, name string) (*api.Job, error) {
job, err = a.Get(ctx, name)
return err
})
return job, err
if err != nil {
return nil, err
}
return job, nil
}

func (r *Retry) Delete(ctx context.Context, name string) error {
Expand All @@ -72,7 +75,10 @@ func (r *Retry) List(ctx context.Context, prefix string) (*api.ListResponse, err
resp, err = a.List(ctx, prefix)
return err
})
return resp, err
if err != nil {
return nil, err
}
return resp, nil
}

func (r *Retry) DeliverablePrefixes(ctx context.Context, prefixes ...string) (context.CancelFunc, error) {
Expand All @@ -82,7 +88,10 @@ func (r *Retry) DeliverablePrefixes(ctx context.Context, prefixes ...string) (co
cancel, err = a.DeliverablePrefixes(ctx, prefixes...)
return err
})
return cancel, err
if err != nil {
return nil, err
}
return cancel, nil
}

func (r *Retry) handle(ctx context.Context, fn func(internalapi.Interface) error) error {
Expand Down
15 changes: 14 additions & 1 deletion internal/scheduler/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,24 @@ type Builder struct {
// clock is the clock used to get the current time. Used for manipulating
// time in tests.
clock clock.Clock

// parser parses job schedules.
parser cron.Parser
}

// NewBuilder creates a new scheduler builder.
func NewBuilder() *Builder {
return &Builder{
clock: clock.RealClock{},
parser: cron.NewParser(
cron.Second |
cron.Minute |
cron.Hour |
cron.Dom |
cron.Month |
cron.Dow |
cron.Descriptor,
),
}
}

Expand All @@ -43,7 +55,8 @@ func (b *Builder) Schedule(job *stored.Job) (Interface, error) {
}, nil
}

cronSched, err := cron.ParseStandard(job.GetJob().GetSchedule())
cronSched, err := b.parser.Parse(job.GetJob().GetSchedule())
//cronSched, err := cron.ParseStandard(job.GetJob().GetSchedule())
if err != nil {
return nil, err
}
Expand Down
32 changes: 31 additions & 1 deletion internal/scheduler/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ func Test_Schedule(t *testing.T) {

cronSched, err := cron.ParseStandard("@every 1h")
require.NoError(t, err)
cronSched2, err := cron.NewParser(
cron.Second |
cron.Minute |
cron.Hour |
cron.Dom |
cron.Month |
cron.Dow |
cron.Descriptor,
).Parse("1 2 3 4 5 6")
require.NoError(t, err)

tests := map[string]struct {
job *stored.Job
Expand Down Expand Up @@ -82,6 +92,25 @@ func Test_Schedule(t *testing.T) {
},
expErr: false,
},
"if schedule with cron, expect repeats with exp nil": {
job: &stored.Job{
Begin: &stored.Job_Start{
Start: timestamppb.New(now),
},
Expiration: nil,
Job: &api.Job{
Schedule: ptr.Of("1 2 3 4 5 6"),
Repeats: ptr.Of(uint32(100)),
},
},
expScheduler: &repeats{
start: ptr.Of(now),
exp: nil,
cron: cronSched2,
total: ptr.Of(uint32(100)),
},
expErr: false,
},
"if bad schedule string, expect error": {
job: &stored.Job{
Begin: &stored.Job_Start{
Expand All @@ -102,7 +131,8 @@ func Test_Schedule(t *testing.T) {
testInLoop := test
t.Run(name, func(t *testing.T) {
t.Parallel()
builder := &Builder{clock: clock}
builder := NewBuilder()
builder.clock = clock
gotScheduler, gotErr := builder.Schedule(testInLoop.job)
assert.Equal(t, testInLoop.expScheduler, gotScheduler)
assert.Equal(t, testInLoop.expErr, gotErr != nil, "%v", gotErr)
Expand Down
Loading