Skip to content

Commit

Permalink
fix(operations): ignore empty lease error when listing (#650)
Browse files Browse the repository at this point in the history
When listing active operations, the internal handler fetches operation leases
to hydrate the operations with this info (useful for detecting when operation
is about to finish/expire). However, when listing the lease might have expired
thus it will throw an error that we don't want. Thus, ignoring lease not found
when listing active operations
  • Loading branch information
hspedro authored Nov 25, 2024
1 parent 0f40a20 commit 953327b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions internal/core/services/operations/operation_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,14 @@ func (om *OperationManager) ListSchedulerPendingOperations(ctx context.Context,
func (om *OperationManager) ListSchedulerActiveOperations(ctx context.Context, schedulerName string) ([]*operation.Operation, error) {
ops, err := om.Storage.ListSchedulerActiveOperations(ctx, schedulerName)
if err != nil {
return nil, fmt.Errorf("failed get active operations list fort scheduler %s : %w", schedulerName, err)
return nil, fmt.Errorf("failed get active operations list for scheduler %s : %w", schedulerName, err)
}
if len(ops) == 0 {
return []*operation.Operation{}, err
}
err = om.addOperationsLeaseData(ctx, schedulerName, ops)
if err != nil {
return nil, err
om.Logger.With(zap.String(logs.LogFieldSchedulerName, schedulerName), zap.Error(err)).Warn("failed to add operations lease data")
}
return ops, nil
}
Expand Down
4 changes: 2 additions & 2 deletions internal/core/services/operations/operation_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ func TestListSchedulerActiveOperations(t *testing.T) {
require.Error(t, err, fmt.Errorf("failed get active operations list fort scheduler %s : %w", schedulerName, errors.New("some error")))
})

t.Run("it returns error when some error occurs in operation lease storage", func(t *testing.T) {
t.Run("it does not return error when some error occurs in operation lease storage", func(t *testing.T) {
mockCtrl := gomock.NewController(t)

operationFlow := mockports.NewMockOperationFlow(mockCtrl)
Expand All @@ -613,7 +613,7 @@ func TestListSchedulerActiveOperations(t *testing.T) {
operationStorage.EXPECT().ListSchedulerActiveOperations(ctx, schedulerName).Return(operationsResult, nil)
operationLeaseStorage.EXPECT().FetchOperationsLease(ctx, schedulerName, operationsResult[0].ID, operationsResult[1].ID, operationsResult[2].ID).Return([]*operation.OperationLease{}, errors.New("some error"))
_, err := opManager.ListSchedulerActiveOperations(ctx, schedulerName)
require.Error(t, err, fmt.Errorf("failed to fetch operations lease for scheduler %s: %w", schedulerName, errors.New("some error")))
require.NoError(t, err)
})

}
Expand Down

0 comments on commit 953327b

Please sign in to comment.