-
Notifications
You must be signed in to change notification settings - Fork 72
/
filegen.go
52 lines (42 loc) · 1.42 KB
/
filegen.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
package main
import (
sp "github.com/scipipe/scipipe"
)
func main() {
wf := sp.NewWorkflow("filegenwf", 4)
fq := NewFileIPGenerator(wf, "hej1.txt", "hej2.txt", "hej3.txt")
fw := sp.NewProc(wf, "filewriter", "echo {i:in} > {o:out}")
fw.SetPathCustom("out", func(t *sp.Task) string { return t.InPath("in") })
fw.In("in").Connect(fq.Out())
wf.Run()
}
// --------------------------------------------------------------------------------
// FileIPGenerator helper process
// --------------------------------------------------------------------------------
// FileIPGenerator is initialized by a set of strings with file paths, and from that will
// return instantiated (generated) FileIP on its Out-port, when run.
type FileIPGenerator struct {
sp.BaseProcess
FilePaths []string
}
// NewFileIPGenerator initializes a new FileIPGenerator component from a list of file paths
func NewFileIPGenerator(wf *sp.Workflow, name string, filePaths ...string) (p *FileIPGenerator) {
p = &FileIPGenerator{
BaseProcess: sp.NewBaseProcess(wf, name),
FilePaths: filePaths,
}
p.InitOutPort(p, "out")
wf.AddProc(p)
return p
}
// Out returns the out-port of the FileIPGenerator
func (p *FileIPGenerator) Out() *sp.OutPort {
return p.OutPort("out")
}
// Run runs the FileIPGenerator process, returning instantiated FileIP
func (p *FileIPGenerator) Run() {
defer p.Out().Close()
for _, fp := range p.FilePaths {
p.Out().Send(sp.NewFileIP(fp))
}
}