Skip to content

Commit

Permalink
set updated array node phase for task exec event
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Dittamo <[email protected]>
  • Loading branch information
pvditt committed Jun 5, 2024
1 parent 25c3596 commit 9f4306a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
28 changes: 17 additions & 11 deletions flytepropeller/pkg/controller/nodes/array/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -564,17 +564,7 @@ func (a *arrayNodeHandler) Handle(ctx context.Context, nCtx interfaces.NodeExecu
// report to admin through a TaskExecutionEvent.
if eventRecorder.finalizeRequired(ctx) {
// determine task phase from ArrayNodePhase
taskPhase := idlcore.TaskExecution_UNDEFINED
switch currentArrayNodePhase {
case v1alpha1.ArrayNodePhaseNone:
taskPhase = idlcore.TaskExecution_QUEUED
case v1alpha1.ArrayNodePhaseExecuting:
taskPhase = idlcore.TaskExecution_RUNNING
case v1alpha1.ArrayNodePhaseSucceeding:
taskPhase = idlcore.TaskExecution_SUCCEEDED
case v1alpha1.ArrayNodePhaseFailing:
taskPhase = idlcore.TaskExecution_FAILED
}
taskPhase := mapTaskPhase(arrayNodeState.Phase)

// if the ArrayNode phase has changed we need to reset the taskPhaseVersion to 0, otherwise
// increment it if we detect any changes in subNode state.
Expand Down Expand Up @@ -641,6 +631,22 @@ func New(nodeExecutor interfaces.Node, eventConfig *config.EventConfig, scope pr
}, nil
}

func mapTaskPhase(arrayNodePhase v1alpha1.ArrayNodePhase) idlcore.TaskExecution_Phase {
taskPhase := idlcore.TaskExecution_UNDEFINED
switch arrayNodePhase {
case v1alpha1.ArrayNodePhaseNone:
taskPhase = idlcore.TaskExecution_QUEUED

Check warning on line 638 in flytepropeller/pkg/controller/nodes/array/handler.go

View check run for this annotation

Codecov / codecov/patch

flytepropeller/pkg/controller/nodes/array/handler.go#L637-L638

Added lines #L637 - L638 were not covered by tests
case v1alpha1.ArrayNodePhaseExecuting:
taskPhase = idlcore.TaskExecution_RUNNING
case v1alpha1.ArrayNodePhaseSucceeding:
taskPhase = idlcore.TaskExecution_SUCCEEDED
case v1alpha1.ArrayNodePhaseFailing:
taskPhase = idlcore.TaskExecution_FAILED
}

return taskPhase
}

// buildArrayNodeContext creates a custom environment to execute the ArrayNode subnode. This is uniquely required for
// the arrayNodeHandler because we require the same node execution entrypoint (ie. recursiveNodeExecutor.RecursiveNodeHandler)
// but need many different execution details, for example setting input values as a singular item rather than a collection,
Expand Down
2 changes: 2 additions & 0 deletions flytepropeller/pkg/controller/nodes/array/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ func TestHandleArrayNodePhaseNone(t *testing.T) {

if len(test.expectedExternalResourcePhases) > 0 {
assert.Equal(t, 1, len(eventRecorder.taskExecutionEvents))
assert.Equal(t, mapTaskPhase(test.expectedArrayNodePhase), eventRecorder.taskExecutionEvents[0].Phase)

externalResources := eventRecorder.taskExecutionEvents[0].Metadata.GetExternalResources()
assert.Equal(t, len(test.expectedExternalResourcePhases), len(externalResources))
Expand Down Expand Up @@ -753,6 +754,7 @@ func TestHandleArrayNodePhaseExecuting(t *testing.T) {

if len(test.expectedExternalResourcePhases) > 0 {
assert.Equal(t, 1, len(eventRecorder.taskExecutionEvents))
assert.Equal(t, mapTaskPhase(test.expectedArrayNodePhase), eventRecorder.taskExecutionEvents[0].Phase)

externalResources := eventRecorder.taskExecutionEvents[0].Metadata.GetExternalResources()
assert.Equal(t, len(test.expectedExternalResourcePhases), len(externalResources))
Expand Down

0 comments on commit 9f4306a

Please sign in to comment.