Skip to content

Commit

Permalink
fix: Address review comment
Browse files Browse the repository at this point in the history
Signed-off-by: Jack Chen <[email protected]>
  • Loading branch information
jackchenjc committed Sep 10, 2024
1 parent f09aad0 commit c6482e6
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type SchedulerManager interface {
StartScheduleJobByName(name, correlationId string) errors.EdgeX
StopScheduleJobByName(name, correlationId string) errors.EdgeX
TriggerScheduleJobByName(name, correlationId string) errors.EdgeX
ValidateScheduleJob(job models.ScheduleJob) errors.EdgeX
ValidateUpdatingScheduleJob(job models.ScheduleJob) errors.EdgeX

Shutdown(correlationId string) errors.EdgeX
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 3 additions & 8 deletions internal/support/cronscheduler/infrastructure/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,8 @@ func (m *manager) AddScheduleJob(job models.ScheduleJob, correlationId string) e

// UpdateScheduleJob updates a ScheduleJob in the scheduler manager
func (m *manager) UpdateScheduleJob(job models.ScheduleJob, correlationId string) errors.EdgeX {
_, err := m.getSchedulerByJobName(job.Name)
if err != nil {
return errors.NewCommonEdgeXWrapper(err)
}

// Validate the ScheduleJob before updating it
if err := m.ValidateScheduleJob(job); err != nil {
if err := m.ValidateUpdatingScheduleJob(job); err != nil {
return errors.NewCommonEdgeX(errors.KindContractInvalid, "failed to validate the scheduled job", err)
}

Expand Down Expand Up @@ -178,8 +173,8 @@ func (m *manager) Shutdown(correlationId string) errors.EdgeX {
return nil
}

// ValidateScheduleJob validates the ScheduleJob that will be updated, this function mainly checks the definition and actions of the ScheduleJob with gocron
func (m *manager) ValidateScheduleJob(job models.ScheduleJob) errors.EdgeX {
// ValidateUpdatingScheduleJob validates the ScheduleJob that will be updated, this function mainly checks the definition and actions of the ScheduleJob with gocron
func (m *manager) ValidateUpdatingScheduleJob(job models.ScheduleJob) errors.EdgeX {
if job.Name == "" && job.Id == "" {
return errors.NewCommonEdgeX(errors.KindContractInvalid, "name or ID is required", nil)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/support/cronscheduler/infrastructure/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func validScheduleJob() models.ScheduleJob {
}
}

func TestValidateScheduleJob(t *testing.T) {
func TestValidateUpdatingScheduleJob(t *testing.T) {
dic := mockDic()
mockManager := NewManager(dic)

Expand Down Expand Up @@ -148,7 +148,7 @@ func TestValidateScheduleJob(t *testing.T) {
}
for _, testCase := range tests {
t.Run(testCase.name, func(t *testing.T) {
err := mockManager.ValidateScheduleJob(testCase.job)
err := mockManager.ValidateUpdatingScheduleJob(testCase.job)
if testCase.expectedError {
assert.Error(t, err)
} else {
Expand Down

0 comments on commit c6482e6

Please sign in to comment.