From c6482e65d89cef554284ac0e5179b1f39df8465d Mon Sep 17 00:00:00 2001 From: Jack Chen Date: Tue, 10 Sep 2024 17:54:20 +0800 Subject: [PATCH] fix: Address review comment Signed-off-by: Jack Chen --- .../infrastructure/interfaces/SchedulerManager.go | 2 +- .../interfaces/mocks/SchedulerManager.go | 6 +++--- .../support/cronscheduler/infrastructure/manager.go | 11 +++-------- .../cronscheduler/infrastructure/manager_test.go | 4 ++-- 4 files changed, 9 insertions(+), 14 deletions(-) diff --git a/internal/support/cronscheduler/infrastructure/interfaces/SchedulerManager.go b/internal/support/cronscheduler/infrastructure/interfaces/SchedulerManager.go index 36e08f2b1f..733c041b89 100644 --- a/internal/support/cronscheduler/infrastructure/interfaces/SchedulerManager.go +++ b/internal/support/cronscheduler/infrastructure/interfaces/SchedulerManager.go @@ -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 } diff --git a/internal/support/cronscheduler/infrastructure/interfaces/mocks/SchedulerManager.go b/internal/support/cronscheduler/infrastructure/interfaces/mocks/SchedulerManager.go index ec741f2697..84ecb02bb4 100644 --- a/internal/support/cronscheduler/infrastructure/interfaces/mocks/SchedulerManager.go +++ b/internal/support/cronscheduler/infrastructure/interfaces/mocks/SchedulerManager.go @@ -155,12 +155,12 @@ func (_m *SchedulerManager) UpdateScheduleJob(job models.ScheduleJob, correlatio return r0 } -// ValidateScheduleJob provides a mock function with given fields: job -func (_m *SchedulerManager) ValidateScheduleJob(job models.ScheduleJob) errors.EdgeX { +// ValidateUpdatingScheduleJob provides a mock function with given fields: job +func (_m *SchedulerManager) ValidateUpdatingScheduleJob(job models.ScheduleJob) errors.EdgeX { ret := _m.Called(job) if len(ret) == 0 { - panic("no return value specified for ValidateScheduleJob") + panic("no return value specified for ValidateUpdatingScheduleJob") } var r0 errors.EdgeX diff --git a/internal/support/cronscheduler/infrastructure/manager.go b/internal/support/cronscheduler/infrastructure/manager.go index 86b4b3b6f6..8643480aaf 100644 --- a/internal/support/cronscheduler/infrastructure/manager.go +++ b/internal/support/cronscheduler/infrastructure/manager.go @@ -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) } @@ -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) } diff --git a/internal/support/cronscheduler/infrastructure/manager_test.go b/internal/support/cronscheduler/infrastructure/manager_test.go index 74bdc25f2a..ce2db170fb 100644 --- a/internal/support/cronscheduler/infrastructure/manager_test.go +++ b/internal/support/cronscheduler/infrastructure/manager_test.go @@ -99,7 +99,7 @@ func validScheduleJob() models.ScheduleJob { } } -func TestValidateScheduleJob(t *testing.T) { +func TestValidateUpdatingScheduleJob(t *testing.T) { dic := mockDic() mockManager := NewManager(dic) @@ -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 {