Skip to content

Commit

Permalink
unfactor Name back to ID
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Leader committed Nov 1, 2023
1 parent a9e4368 commit 7cb26db
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 29 deletions.
6 changes: 3 additions & 3 deletions internal/step/dummy/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ func (s *stageChangeHandler) OnStepComplete(
panic(fmt.Errorf("invalid previous stage: %s", previousStage))
}
if previousStageOutputID == nil {
panic(fmt.Errorf("no previous stage output Name"))
panic(fmt.Errorf("no previous stage output ID"))
}
if *previousStageOutputID != "success" {
panic(fmt.Errorf("invalid previous stage output Name: %s", *previousStageOutputID))
panic(fmt.Errorf("invalid previous stage output ID: %s", *previousStageOutputID))
}
if previousStageOutput == nil {
panic(fmt.Errorf("no previous stage output Name"))
panic(fmt.Errorf("no previous stage output ID"))
}
message := (*previousStageOutput).(map[string]any)["message"].(string)
s.message <- message
Expand Down
2 changes: 1 addition & 1 deletion internal/step/foreach/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ func (r *runningStep) run() {
}

r.logger.Debugf("Executing item %d...", i)
// Ignore the output Name here because it can only be "success"
// Ignore the output ID here because it can only be "success"
_, outputData, err := r.workflow.Execute(r.ctx, input)
r.lock.Lock()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/step/lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (l Lifecycle[StageType]) DAG() (dgraph.DirectedGraph[StageType], error) {

// lifecycleStage is a helper interface for being able to construct a DAG from a lifecycle.
type lifecycleStage interface {
// Identifier returns the Name of the stage.
// Identifier returns the ID of the stage.
Identifier() string
// NextStageIDs returns the next stage identifiers.
NextStageIDs() []string
Expand Down
2 changes: 1 addition & 1 deletion internal/step/plugin/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ func (r *runnableStep) Lifecycle(input map[string]any) (result step.Lifecycle[st
cancelSignal := stepSchema.SignalHandlers()[plugin.CancellationSignalSchema.ID()]
if cancelSignal == nil {
// Not present
stopIfProperty.Disable(fmt.Sprintf("Cancel signal with Name '%s' is not present in plugin '%s', step '%s'. Signal handler IDs present: %v",
stopIfProperty.Disable(fmt.Sprintf("Cancel signal with ID '%s' is not present in plugin '%s', step '%s'. Signal handler IDs present: %v",
plugin.CancellationSignalSchema.ID(), r.source, stepID, reflect.ValueOf(stepSchema.SignalHandlers()).MapKeys()))
} else if err := plugin.CancellationSignalSchema.DataSchemaValue.ValidateCompatibility(cancelSignal.DataSchemaValue); err != nil {
// Present but incompatible
Expand Down
16 changes: 8 additions & 8 deletions internal/step/plugin/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ func (s *deployFailStageChangeHandler) OnStepComplete(
panic(fmt.Errorf("invalid previous stage: %s", previousStage))
}
if previousStageOutputID == nil {
panic(fmt.Errorf("no previous stage output Name"))
panic(fmt.Errorf("no previous stage output ID"))
}
if *previousStageOutputID != "error" {
panic(fmt.Errorf("invalid previous stage output Name: %s", *previousStageOutputID))
panic(fmt.Errorf("invalid previous stage output ID: %s", *previousStageOutputID))
}
if previousStageOutput == nil {
panic(fmt.Errorf("no previous stage output Name"))
panic(fmt.Errorf("no previous stage output ID"))
}
message := (*previousStageOutput).(plugin.DeployFailed).Error

Expand All @@ -65,13 +65,13 @@ func (s *startFailStageChangeHandler) OnStepComplete(
panic(fmt.Errorf("invalid previous stage: %s", previousStage))
}
if previousStageOutputID == nil {
panic(fmt.Errorf("no previous stage output Name"))
panic(fmt.Errorf("no previous stage output ID"))
}
if *previousStageOutputID != "error" {
panic(fmt.Errorf("invalid previous stage output Name: %s", *previousStageOutputID))
}
if previousStageOutput == nil {
panic(fmt.Errorf("no previous stage output Name"))
panic(fmt.Errorf("no previous stage output ID"))
}

message := (*previousStageOutput).(plugin.Crashed).Output
Expand All @@ -98,13 +98,13 @@ func (s *stageChangeHandler) OnStepComplete(
panic(fmt.Errorf("invalid previous stage: %s", previousStage))
}
if previousStageOutputID == nil {
panic(fmt.Errorf("no previous stage output Name"))
panic(fmt.Errorf("no previous stage output ID"))
}
if *previousStageOutputID != "success" {
panic(fmt.Errorf("invalid previous stage output Name: %s", *previousStageOutputID))
panic(fmt.Errorf("invalid previous stage output ID: %s", *previousStageOutputID))
}
if previousStageOutput == nil {
panic(fmt.Errorf("no previous stage output Name"))
panic(fmt.Errorf("no previous stage output ID"))
}
message := (*previousStageOutput).(map[any]any)["message"].(string)

Expand Down
2 changes: 1 addition & 1 deletion workflow/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type ExecutableWorkflow interface {

// Execute runs a workflow until it finishes or until the context expires with the specified input. The input
// must only contain primitives (float, int, bool, string, map, slice) and may not contain structs and other
// elements. The output will consist of the output Name, the returned output data corresponding to the output IDs
// elements. The output will consist of the output ID, the returned output data corresponding to the output IDs
// schema, or if an error happened, the error.
Execute(
ctx context.Context,
Expand Down
8 changes: 4 additions & 4 deletions workflow/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type Workflow struct {
// Steps contains the possible steps in this workflow. The data set must contain a valid step structure where the
// inputs to stages may consist only of primitive types and expressions.
Steps map[string]any `json:"steps"`
// Outputs lets you define one or more outputs. The outputs should be keyed by their output Name (e.g. "success") and
// Outputs lets you define one or more outputs. The outputs should be keyed by their output ID (e.g. "success") and
// the value should be the data you wish to output. The data may contain expressions to construct the output.
Outputs map[string]any `json:"outputs"`
// OutputSchema is an optional override for the automatically inferred output schema from the Outputs data and
Expand Down Expand Up @@ -182,7 +182,7 @@ type DAGItem struct {
StepID string
// StageID is the stage of the step provider this item refers to.
StageID string
// OutputID is the Name of the output of the step stage.
// OutputID is the ID of the output of the step stage.
OutputID string
// OutputSchema contains the output-specific schema for this item.
OutputSchema schema.StepOutput
Expand Down Expand Up @@ -212,12 +212,12 @@ func (d DAGItem) String() string {
}
}

// GetStageNodeID returns the DAG node Name for a stage.
// GetStageNodeID returns the DAG node ID for a stage.
func GetStageNodeID(stepID string, stageID string) string {
return fmt.Sprintf("steps.%s.%s", stepID, stageID)
}

// GetOutputNodeID returns the DAG node Name for a stage output.
// GetOutputNodeID returns the DAG node ID for a stage output.
func GetOutputNodeID(stepID string, stageID string, outputID string) string {
return fmt.Sprintf("steps.%s.%s.%s", stepID, stageID, outputID)
}
Expand Down
20 changes: 10 additions & 10 deletions workflow/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,31 +260,31 @@ func (l *loopState) onStageComplete(stepID string, previousStage *string, previo
}
stageNode, err := l.dag.GetNodeByID(GetStageNodeID(stepID, *previousStage))
if err != nil {
l.logger.Errorf("Failed to get stage node Name %s (%w)", GetStageNodeID(stepID, *previousStage), err)
l.recentErrors <- fmt.Errorf("failed to get stage node Name %s (%w)", GetStageNodeID(stepID, *previousStage), err)
l.logger.Errorf("Failed to get stage node ID %s (%w)", GetStageNodeID(stepID, *previousStage), err)
l.recentErrors <- fmt.Errorf("failed to get stage node ID %s (%w)", GetStageNodeID(stepID, *previousStage), err)
l.cancel()
return
}
l.logger.Debugf("Removed node '%s' from the DAG", stageNode.ID())
if err := stageNode.Remove(); err != nil {
l.logger.Errorf("Failed to remove stage node Name %s (%w)", stageNode.ID(), err)
l.recentErrors <- fmt.Errorf("failed to remove stage node Name %s (%w)", stageNode.ID(), err)
l.logger.Errorf("Failed to remove stage node ID %s (%w)", stageNode.ID(), err)
l.recentErrors <- fmt.Errorf("failed to remove stage node ID %s (%w)", stageNode.ID(), err)
l.cancel()
return
}
if previousStageOutputID != nil {
outputNode, err := l.dag.GetNodeByID(GetOutputNodeID(stepID, *previousStage, *previousStageOutputID))
if err != nil {
l.logger.Errorf("Failed to get output node Name %s (%w)", GetStageNodeID(stepID, *previousStage), err)
l.recentErrors <- fmt.Errorf("failed to get output node Name %s (%w)", GetStageNodeID(stepID, *previousStage), err)
l.logger.Errorf("Failed to get output node ID %s (%w)", GetStageNodeID(stepID, *previousStage), err)
l.recentErrors <- fmt.Errorf("failed to get output node ID %s (%w)", GetStageNodeID(stepID, *previousStage), err)
l.cancel()
return
}
// Removes the node from the DAG. This results in the nodes not having inbound connections, allowing them to be processed.
l.logger.Debugf("Removed node '%s' from the DAG", outputNode.ID())
if err := outputNode.Remove(); err != nil {
l.logger.Errorf("Failed to remove output node Name %s (%w)", outputNode.ID(), err)
l.recentErrors <- fmt.Errorf("failed to remove output node Name %s (%w)", outputNode.ID(), err)
l.logger.Errorf("Failed to remove output node ID %s (%w)", outputNode.ID(), err)
l.recentErrors <- fmt.Errorf("failed to remove output node ID %s (%w)", outputNode.ID(), err)
l.cancel()
return
}
Expand All @@ -293,7 +293,7 @@ func (l *loopState) onStageComplete(stepID string, previousStage *string, previo
if stepLogConfig != nil {
l.logger.Writef(
stepLogConfig.LogLevel,
"Output Name for step \"%s\" is \"%s\".\nOutput data: \"%s\"",
"Output ID for step \"%s\" is \"%s\".\nOutput data: \"%s\"",
stepID,
*previousStageOutputID,
*previousStageOutput,
Expand Down Expand Up @@ -362,7 +362,7 @@ func (l *loopState) notifySteps() { //nolint:gocognit
// This check is here just to make sure it has the required fields set
if node.Item().StepID == "" || node.Item().StageID == "" {
// This shouldn't happen
panic("Step or stage Name missing")
panic("Step or stage ID missing")
}

stageInputData := untypedInputData.(map[any]any)
Expand Down

0 comments on commit 7cb26db

Please sign in to comment.