mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-12 12:15:00 +00:00
36 lines
795 B
Go
36 lines
795 B
Go
package parse
|
|
|
|
import "fmt"
|
|
|
|
// ParallelNode executes a list of child nodes in parallel.
|
|
type ParallelNode struct {
|
|
NodeType `json:"type"`
|
|
|
|
Body []Node `json:"body"` // nodes for parallel evaluation.
|
|
Limit int `json:"limit"` // limit for parallel evaluation.
|
|
}
|
|
|
|
func NewParallelNode() *ParallelNode {
|
|
return &ParallelNode{NodeType: NodeParallel}
|
|
}
|
|
|
|
func (n *ParallelNode) Append(node Node) *ParallelNode {
|
|
n.Body = append(n.Body, node)
|
|
return n
|
|
}
|
|
|
|
func (n *ParallelNode) SetLimit(limit int) *ParallelNode {
|
|
n.Limit = limit
|
|
return n
|
|
}
|
|
|
|
func (n *ParallelNode) Validate() error {
|
|
switch {
|
|
case n.NodeType != NodeParallel:
|
|
return fmt.Errorf("Parallel Node uses an invalid type")
|
|
case len(n.Body) == 0:
|
|
return fmt.Errorf("Parallel Node body is empty")
|
|
default:
|
|
return nil
|
|
}
|
|
}
|