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

feat: Add AutoTriggerMissedRecords to ScheduleJob #927

Merged
merged 1 commit into from
Sep 9, 2024
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
34 changes: 19 additions & 15 deletions dtos/schedulejob.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,26 @@ import (
)

type ScheduleJob struct {
DBTimestamp `json:",inline"`
Id string `json:"id,omitempty" validate:"omitempty,uuid"`
Name string `json:"name" validate:"edgex-dto-none-empty-string"`
Definition ScheduleDef `json:"definition" validate:"required"`
Actions []ScheduleAction `json:"actions" validate:"required,gt=0,dive"`
AdminState string `json:"adminState" validate:"omitempty,oneof='LOCKED' 'UNLOCKED'"`
Labels []string `json:"labels,omitempty"`
Properties map[string]any `json:"properties,omitempty"`
DBTimestamp `json:",inline"`
Id string `json:"id,omitempty" validate:"omitempty,uuid"`
Name string `json:"name" validate:"edgex-dto-none-empty-string"`
Definition ScheduleDef `json:"definition" validate:"required"`
AutoTriggerMissedRecords bool `json:"autoTriggerMissedRecords,omitempty"`
Actions []ScheduleAction `json:"actions" validate:"required,gt=0,dive"`
AdminState string `json:"adminState" validate:"omitempty,oneof='LOCKED' 'UNLOCKED'"`
Labels []string `json:"labels,omitempty"`
Properties map[string]any `json:"properties,omitempty"`
}

type UpdateScheduleJob struct {
Id *string `json:"id" validate:"required_without=Name,edgex-dto-uuid"`
Name *string `json:"name" validate:"required_without=Id,edgex-dto-none-empty-string"`
Definition *ScheduleDef `json:"definition" validate:"omitempty"`
Actions []ScheduleAction `json:"actions,omitempty"`
AdminState *string `json:"adminState" validate:"omitempty,oneof='LOCKED' 'UNLOCKED'"`
Labels []string `json:"labels,omitempty"`
Properties map[string]any `json:"properties,omitempty"`
Id *string `json:"id" validate:"required_without=Name,edgex-dto-uuid"`
Name *string `json:"name" validate:"required_without=Id,edgex-dto-none-empty-string"`
Definition *ScheduleDef `json:"definition" validate:"omitempty"`
AutoTriggerMissedRecords *bool `json:"autoTriggerMissedRecords,omitempty"`
Actions []ScheduleAction `json:"actions,omitempty"`
AdminState *string `json:"adminState" validate:"omitempty,oneof='LOCKED' 'UNLOCKED'"`
Labels []string `json:"labels,omitempty"`
Properties map[string]any `json:"properties,omitempty"`
}

// Validate satisfies the Validator interface
Expand Down Expand Up @@ -201,6 +203,7 @@ func ToScheduleJobModel(dto ScheduleJob) models.ScheduleJob {
model.Id = dto.Id
model.Name = dto.Name
model.Definition = ToScheduleDefModel(dto.Definition)
model.AutoTriggerMissedRecords = dto.AutoTriggerMissedRecords
model.Actions = ToScheduleActionModels(dto.Actions)
model.AdminState = models.AssignAdminState(dto.AdminState)
model.Labels = dto.Labels
Expand All @@ -215,6 +218,7 @@ func FromScheduleJobModelToDTO(model models.ScheduleJob) ScheduleJob {
dto.Id = model.Id
dto.Name = model.Name
dto.Definition = FromScheduleDefModelToDTO(model.Definition)
dto.AutoTriggerMissedRecords = model.AutoTriggerMissedRecords
dto.Actions = FromScheduleActionModelsToDTOs(model.Actions)
dto.AdminState = string(model.AdminState)
dto.Labels = model.Labels
Expand Down
26 changes: 14 additions & 12 deletions dtos/schedulejob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,22 @@ var scheduleCronDefModel = models.CronScheduleDef{

var (
scheduleJob = ScheduleJob{
DBTimestamp: DBTimestamp{},
Id: TestUUID,
Name: jobName,
Definition: scheduleIntervalDef,
Actions: []ScheduleAction{scheduleActionEdgeXMessageBus},
AdminState: testAdminState,
DBTimestamp: DBTimestamp{},
Id: TestUUID,
Name: jobName,
Definition: scheduleIntervalDef,
AutoTriggerMissedRecords: true,
Actions: []ScheduleAction{scheduleActionEdgeXMessageBus},
AdminState: testAdminState,
}
scheduleJobModel = models.ScheduleJob{
DBTimestamp: models.DBTimestamp{},
Id: TestUUID,
Name: jobName,
Definition: scheduleIntervalDefModel,
Actions: []models.ScheduleAction{scheduleActionEdgeXMessageBusModel},
AdminState: models.AdminState(testAdminState),
DBTimestamp: models.DBTimestamp{},
Id: TestUUID,
Name: jobName,
Definition: scheduleIntervalDefModel,
AutoTriggerMissedRecords: true,
Actions: []models.ScheduleAction{scheduleActionEdgeXMessageBusModel},
AdminState: models.AdminState(testAdminState),
}
)

Expand Down
47 changes: 25 additions & 22 deletions models/schedulejob.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,27 @@ import (

type ScheduleJob struct {
DBTimestamp
Id string
Name string
Definition ScheduleDef
Actions []ScheduleAction
AdminState AdminState
Labels []string
Properties map[string]any
Id string
Name string
Definition ScheduleDef
AutoTriggerMissedRecords bool
Actions []ScheduleAction
AdminState AdminState
Labels []string
Properties map[string]any
}

func (scheduleJob *ScheduleJob) UnmarshalJSON(b []byte) error {
var alias struct {
DBTimestamp
Id string
Name string
Definition any
Actions []any
AdminState AdminState
Labels []string
Properties map[string]any
Id string
Name string
Definition any
AutoTriggerMissedRecords bool
Actions []any
AdminState AdminState
Labels []string
Properties map[string]any
}

if err := json.Unmarshal(b, &alias); err != nil {
Expand All @@ -55,14 +57,15 @@ func (scheduleJob *ScheduleJob) UnmarshalJSON(b []byte) error {
}

*scheduleJob = ScheduleJob{
DBTimestamp: alias.DBTimestamp,
Id: alias.Id,
Name: alias.Name,
Definition: def,
Actions: actions,
AdminState: alias.AdminState,
Labels: alias.Labels,
Properties: alias.Properties,
DBTimestamp: alias.DBTimestamp,
Id: alias.Id,
Name: alias.Name,
Definition: def,
AutoTriggerMissedRecords: alias.AutoTriggerMissedRecords,
Actions: actions,
AdminState: alias.AdminState,
Labels: alias.Labels,
Properties: alias.Properties,
}
return nil
}
Expand Down
44 changes: 24 additions & 20 deletions models/schedulejob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,21 +195,23 @@ var deviceControlAction = DeviceControlAction{

func scheduleJobWithINTERVALScheduleDef() ScheduleJob {
return ScheduleJob{
DBTimestamp: DBTimestamp{},
Id: ExampleUUID,
Name: TestScheduleJobName,
Definition: intervalScheduleDef,
Actions: []ScheduleAction{},
DBTimestamp: DBTimestamp{},
Id: ExampleUUID,
Name: TestScheduleJobName,
Definition: intervalScheduleDef,
AutoTriggerMissedRecords: true,
Actions: []ScheduleAction{},
}
}

func scheduleJobWithCRONScheduleDef() ScheduleJob {
return ScheduleJob{
DBTimestamp: DBTimestamp{},
Id: ExampleUUID,
Name: TestScheduleJobName,
Definition: cronScheduleDef,
Actions: []ScheduleAction{},
DBTimestamp: DBTimestamp{},
Id: ExampleUUID,
Name: TestScheduleJobName,
Definition: cronScheduleDef,
AutoTriggerMissedRecords: false,
Actions: []ScheduleAction{},
}
}

Expand All @@ -225,21 +227,23 @@ func scheduleJobWithEDGEXMESSAGEBUSScheduleAction() ScheduleJob {

func scheduleJobWithRESTScheduleAction() ScheduleJob {
return ScheduleJob{
DBTimestamp: DBTimestamp{},
Id: ExampleUUID,
Name: TestScheduleJobName,
Definition: intervalScheduleDef,
Actions: []ScheduleAction{restAction},
DBTimestamp: DBTimestamp{},
Id: ExampleUUID,
Name: TestScheduleJobName,
Definition: intervalScheduleDef,
AutoTriggerMissedRecords: true,
Actions: []ScheduleAction{restAction},
}
}

func scheduleJobWithDEVICECONTROLScheduleAction() ScheduleJob {
return ScheduleJob{
DBTimestamp: DBTimestamp{},
Id: ExampleUUID,
Name: TestScheduleJobName,
Definition: intervalScheduleDef,
Actions: []ScheduleAction{deviceControlAction},
DBTimestamp: DBTimestamp{},
Id: ExampleUUID,
Name: TestScheduleJobName,
Definition: intervalScheduleDef,
AutoTriggerMissedRecords: false,
Actions: []ScheduleAction{deviceControlAction},
}
}

Expand Down