This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 63
/
mock_event_scheduler.go
56 lines (47 loc) · 1.89 KB
/
mock_event_scheduler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package mocks
import (
"context"
"github.com/flyteorg/flyteadmin/pkg/async/schedule/aws"
"github.com/flyteorg/flyteadmin/pkg/async/schedule/interfaces"
runtimeInterfaces "github.com/flyteorg/flyteadmin/pkg/runtime/interfaces"
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
)
type AddScheduleFunc func(ctx context.Context, input interfaces.AddScheduleInput) error
type RemoveScheduleFunc func(ctx context.Context, input interfaces.RemoveScheduleInput) error
type MockEventScheduler struct {
addScheduleFunc AddScheduleFunc
removeScheduleFunc RemoveScheduleFunc
}
func (s *MockEventScheduler) CreateScheduleInput(ctx context.Context, appConfig *runtimeInterfaces.SchedulerConfig,
identifier core.Identifier, schedule *admin.Schedule) (interfaces.AddScheduleInput, error) {
payload, _ := aws.SerializeScheduleWorkflowPayload(
schedule.GetKickoffTimeInputArg(),
admin.NamedEntityIdentifier{
Project: identifier.Project,
Domain: identifier.Domain,
Name: identifier.Name,
})
return interfaces.AddScheduleInput{Identifier: identifier, ScheduleExpression: *schedule, Payload: payload}, nil
}
func (s *MockEventScheduler) AddSchedule(ctx context.Context, input interfaces.AddScheduleInput) error {
if s.addScheduleFunc != nil {
return s.addScheduleFunc(ctx, input)
}
return nil
}
func (s *MockEventScheduler) SetAddScheduleFunc(addScheduleFunc AddScheduleFunc) {
s.addScheduleFunc = addScheduleFunc
}
func (s *MockEventScheduler) RemoveSchedule(ctx context.Context, input interfaces.RemoveScheduleInput) error {
if s.removeScheduleFunc != nil {
return s.removeScheduleFunc(ctx, input)
}
return nil
}
func (s *MockEventScheduler) SetRemoveScheduleFunc(removeScheduleFunc RemoveScheduleFunc) {
s.removeScheduleFunc = removeScheduleFunc
}
func NewMockEventScheduler() interfaces.EventScheduler {
return &MockEventScheduler{}
}