-
Notifications
You must be signed in to change notification settings - Fork 2
/
plotter.go
45 lines (37 loc) · 1 KB
/
plotter.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
package graph
import (
"context"
"github.com/longsolong/flow/pkg/orchestration/job"
"time"
"github.com/longsolong/flow/pkg/orchestration/request"
"github.com/longsolong/flow/pkg/orchestration/standalone/chain"
"github.com/longsolong/flow/pkg/workflow/atom"
"github.com/longsolong/flow/pkg/workflow/dag"
)
// Plotter ...
type Plotter struct {
*dag.DAG
*chain.Chain
done chan struct{}
}
func NewPlotter(name string, version int) (p Plotter) {
p.done = make(chan struct{})
p.DAG = dag.NewDAG(name, version)
p.Chain = chain.NewChain(p.DAG)
return p
}
func (p *Plotter) Done() <-chan struct{} {
return p.done
}
func (p *Plotter) Close() {
close(p.done)
}
func (p *Plotter) NewNode(ctx context.Context, req *request.Request, step atom.Atom, name string, retry uint, retryWait time.Duration) (*dag.Node, error) {
if err := step.Create(ctx, req); err != nil {
return nil, err
}
node := dag.NewNode(step, name, retry, retryWait)
p.DAG.MustAddNode(node)
p.Chain.AddJob(job.NewJob(step))
return node, nil
}