Skip to content

Commit f50ef87

Browse files
authored
validate if scheduler and operations exists when try to cancel operation (#318)
* validate if scheduler and operations exists when try to cancel operation * validate if scheduler and operations exists when try to cancel operation * lint adjustments
1 parent 167ae2c commit f50ef87

File tree

6 files changed

+221
-36
lines changed

6 files changed

+221
-36
lines changed

cmd/managementapi/wire_gen.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/worker/wire_gen.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/core/operations/newschedulerversion/new_scheduler_version_executor_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ func newMockRoomAndSchedulerManager(mockCtrl *gomock.Controller) *mockRoomAndSch
340340
operationStorage := mockports.NewMockOperationStorage(mockCtrl)
341341
operationLeaseStorage := mockports.NewMockOperationLeaseStorage(mockCtrl)
342342
opConfig := operation_manager.OperationManagerConfig{OperationLeaseTtl: time.Millisecond * 1000}
343-
operationManager := operation_manager.New(operationFlow, operationStorage, operations.NewDefinitionConstructors(), operationLeaseStorage, opConfig)
343+
operationManager := operation_manager.New(operationFlow, operationStorage, operations.NewDefinitionConstructors(), operationLeaseStorage, opConfig, schedulerStorage)
344344
schedulerManager := scheduler_manager.NewSchedulerManager(schedulerStorage, operationManager, roomStorage)
345345

346346
return &mockRoomAndSchedulerManager{

internal/core/services/operation_manager/operation_manager.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,19 @@ type OperationManager struct {
4444
LeaseStorage ports.OperationLeaseStorage
4545
Config OperationManagerConfig
4646
OperationDefinitionConstructors map[string]operations.DefinitionConstructor
47+
SchedulerStorage ports.SchedulerStorage
4748
Logger *zap.Logger
4849
}
4950

50-
func New(flow ports.OperationFlow, storage ports.OperationStorage, operationDefinitionConstructors map[string]operations.DefinitionConstructor, leaseStorage ports.OperationLeaseStorage, config OperationManagerConfig) *OperationManager {
51+
func New(flow ports.OperationFlow, storage ports.OperationStorage, operationDefinitionConstructors map[string]operations.DefinitionConstructor, leaseStorage ports.OperationLeaseStorage, config OperationManagerConfig, schedulerStorage ports.SchedulerStorage) *OperationManager {
5152
return &OperationManager{
5253
Flow: flow,
5354
Storage: storage,
5455
OperationDefinitionConstructors: operationDefinitionConstructors,
5556
OperationCancelFunctions: NewOperationCancelFunctions(),
5657
LeaseStorage: leaseStorage,
5758
Config: config,
59+
SchedulerStorage: schedulerStorage,
5860
Logger: zap.L().With(zap.String("component", "service"), zap.String("service", "operation_manager")),
5961
}
6062
}
@@ -174,7 +176,17 @@ func (om *OperationManager) FinishOperation(ctx context.Context, op *operation.O
174176
}
175177

176178
func (om *OperationManager) EnqueueOperationCancellationRequest(ctx context.Context, schedulerName, operationID string) error {
177-
err := om.Flow.EnqueueOperationCancellationRequest(ctx, ports.OperationCancellationRequest{
179+
_, err := om.SchedulerStorage.GetScheduler(ctx, schedulerName)
180+
if err != nil {
181+
return fmt.Errorf("failed to fetch scheduler from storage: %w", err)
182+
}
183+
184+
_, _, err = om.Storage.GetOperation(ctx, schedulerName, operationID)
185+
if err != nil {
186+
return fmt.Errorf("failed to fetch operation from storage: %w", err)
187+
}
188+
189+
err = om.Flow.EnqueueOperationCancellationRequest(ctx, ports.OperationCancellationRequest{
178190
SchedulerName: schedulerName,
179191
OperationID: operationID,
180192
})

0 commit comments

Comments
 (0)