-
Notifications
You must be signed in to change notification settings - Fork 54
/
doc.go
70 lines (58 loc) · 1.64 KB
/
doc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
Package pipeline is used to build multi-staged concurrent workflows with a centralized logging output:
Pipeline
|
| Stages
|
| Steps
The package has three building blocks to create workflows : Pipeline, Stage and Step . A pipeline is a collection of stages and a stage is a
collection of steps. A stage can have either concurrent or sequential steps, while stages are always sequential.
Example Usage:
package main
import (
"github.com/myntra/pipeline"
"fmt"
"time"
)
type work struct {
pipeline.StepContext
id int
}
func (w work) Exec(request *pipeline.Request) *pipeline.Result {
w.Status("work")
time.Sleep(time.Millisecond * 2000)
return &pipeline.Result{}
}
func (w work) Cancel() error {
w.Status("cancel step")
return nil
}
func readPipeline(pipe *pipeline.Pipeline) {
out, err := pipe.Out()
if err != nil {
return
}
progress, err := pipe.GetProgressPercent()
if err != nil {
return
}
for {
select {
case line := <-out:
fmt.Println(line)
case p := <-progress:
fmt.Println("percent done: ", p)
}
}
}
func main() {
workpipe := pipeline.NewProgress("myProgressworkpipe", 1000, time.Second*2)
stage := pipeline.NewStage("mypworkstage", false, false)
stage.AddStep(&work{id: 1})
workpipe.AddStage(stage)
go readPipeline(workpipe)
workpipe.Run()
}
For a detailed guide check Readme.md
*/
package pipeline