MCPcopy Create free account
hub / github.com/The-Pocket/PocketFlow-Go / InternalRun

Method InternalRun

pocketflow.go:822–859  ·  view source on GitHub ↗

InternalRun executes the BatchFlow lifecycle: PrepBatch, Exec(orchestrate per batch), PostBatch.

(ctx *PfContext)

Source from the content-addressed store, hash-verified

820
821// InternalRun executes the BatchFlow lifecycle: PrepBatch, Exec(orchestrate per batch), PostBatch.
822func (bf *BatchFlow) InternalRun(ctx *PfContext) (string, error) {
823 // 1. Run BatchFlow's Prep phase (PrepBatchFunc)
824 // Should return []*pfContext
825 prepBatchResultAny, err := bf.Prep(ctx)
826 if err != nil {
827 return "", newPocketFlowError(fmt.Sprintf("PrepBatch phase failed for BatchFlow %T", bf), err)
828 }
829
830 batchParamsList, ok := prepBatchResultAny.([]map[string]any)
831 if prepBatchResultAny != nil && !ok {
832 return "", newPocketFlowError(fmt.Sprintf("Internal error: PrepBatch phase in BatchFlow %T did not return []*pfContext (%T)", bf, prepBatchResultAny), nil)
833 }
834 if batchParamsList == nil {
835 batchParamsList = []map[string]any{}
836 }
837
838 // 2. Run the orchestration for each item in batchParamsList
839 for i, batchParams := range batchParamsList {
840 // Run the embedded Flow's orchestration logic for each parameter set.
841 // Pass the *original* shared context and current batchParams.
842 _, err := bf.Flow.orchestrate(ctx, batchParams)
843 if err != nil {
844 // If one batch run fails, fail the whole BatchFlow execution
845 return "", newPocketFlowError(fmt.Sprintf("Orchestration failed for batch item %d in %T", i, bf), err)
846 }
847 // Result (lastAction) of individual orchestrate runs is ignored here; side effects matter.
848 }
849
850 // 3. Run BatchFlow's Post phase (PostBatchFunc)
851 // The result of the "Exec" phase semantically is the list itself.
852 execResult := batchParamsList
853 finalAction, err := bf.Post(ctx, prepBatchResultAny, execResult)
854 if err != nil {
855 return "", newPocketFlowError(fmt.Sprintf("PostBatch phase failed for BatchFlow %T", bf), err)
856 }
857
858 return finalAction, nil
859}

Callers 1

RunMethod · 0.95

Calls 4

PrepMethod · 0.95
PostMethod · 0.95
newPocketFlowErrorFunction · 0.85
orchestrateMethod · 0.80

Tested by

no test coverage detected