generated from snivilised/arcadia
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(proxy): add initial sequencing functionality (#48)
- Loading branch information
1 parent
db2ec13
commit 11fbe2f
Showing
2 changed files
with
119 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package proxy | ||
|
||
import ( | ||
"github.com/snivilised/cobrass/src/clif" | ||
"github.com/snivilised/extendio/collections" | ||
) | ||
|
||
type Step interface { | ||
Run() error | ||
} | ||
|
||
type Sequence interface { | ||
RunAll() error | ||
} | ||
|
||
// magickStep knows how to combine parameters together so that the program | ||
// can be invoked correctly; but it does not know how to compose the input | ||
// and output file names; this is the responsibility of the runner, which uses | ||
// the path-finder to accomplish that task. | ||
type magickStep struct { // Step | ||
fileManager *FileManager | ||
program Executor | ||
thirdPartyCL clif.ThirdPartyCommandLine | ||
sourcePath string | ||
outputPath string | ||
journalPath string | ||
} | ||
|
||
func (s *magickStep) Run() error { | ||
positional := []string{s.sourcePath} | ||
|
||
return s.program.Execute(clif.Expand(positional, s.thirdPartyCL)...) | ||
} | ||
|
||
// ExecutionSequence will batch together a list of steps. They are executed within | ||
// the same go routine. The sequence will consist of 1 or more external blocking | ||
// executions. By default, the execution sequence will stop running if the third | ||
// party program returns a non zero result. | ||
type ExecutionSequence struct { // Sequence | ||
iterator collections.Iterator[Step] | ||
} | ||
|
||
func (s *ExecutionSequence) RunAll() error { | ||
// this will continue in the presence of errors .... (TODO change the while condition) | ||
var err error | ||
for entry := s.iterator.Start(); s.iterator.Valid(); entry = s.iterator.Next() { | ||
err = entry.Run() | ||
} | ||
|
||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters