package spindle import ( "context" "tangled.org/core/spindle/models" ) // createPipeline creates a pipeline from given event. // It will call `EvaluateEvent` for all adapters, gather the triggered workflow // runs, and constuct a pipeline record from them. pipeline record. It will // return nil if no workflow run has triggered. // // NOTE: This method won't fail. If `adapter.EvaluateEvent` returns an error, // the error will be logged but won't bubble-up. // // NOTE: Adapters might create sub-event on its own for workflows triggered by // other workflow runs. func (s *Spindle) createPipeline(ctx context.Context, event models.Event) (*models.Pipeline2) { l := s.l pipeline := models.Pipeline2{ Event: event, } // TODO: run in parallel for id, adapter := range s.adapters { runs, err := adapter.EvaluateEvent(ctx, event) if err != nil { l.Error("failed to process trigger from adapter '%s': %w", id, err) } pipeline.WorkflowRuns = append(pipeline.WorkflowRuns, runs...) } if len(pipeline.WorkflowRuns) == 0 { return nil } return &pipeline }