Skip to content

Commit d796032

Browse files
authored
Merge pull request #75 from trickest/feature/output-by-run-id
Download output by run ID
2 parents 936da80 + 0ad70a8 commit d796032

File tree

2 files changed

+49
-16
lines changed

2 files changed

+49
-16
lines changed

README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -217,15 +217,14 @@ Use the **output** command to download the outputs of your particular workflow e
217217
```
218218
trickest output --workflow <workflow_name> --space <space_name> [--config <config_file_path>] [--runs <number>]
219219
```
220-
| Flag | Type | Default | Description |
221-
| ---------- | ------ | ------- | ---------------------------------------------------------------------------------------------------------------------------------- |
222-
| --workflow | string | / | The name of the workflow. |
223-
| --space | string | / | The name of the space to which workflow belongs |
224-
| --config | file | / | YAML file for run configuration |
220+
| Flag | Type | Default | Description |
221+
| ---------- | ------ | ------- | ---------------------------------------------------------------------------------------------------------------------------------- |
222+
| --workflow | string | / | The name of the workflow. |
223+
| --space | string | / | The name of the space to which workflow belongs |
224+
| --config | file | / | YAML file for run configuration |
225+
| --run | string | / | Download output data of a specific run |
225226
| --runs | integer | 1 | The number of executions to be downloaded sorted by newest |
226227

227-
228-
229228

230229
## Output Structure
231230

cmd/output/output.go

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package output
33
import (
44
"encoding/json"
55
"fmt"
6-
"github.com/google/uuid"
76
"io"
87
"io/ioutil"
98
"math"
@@ -17,6 +16,8 @@ import (
1716
"trickest-cli/types"
1817
"trickest-cli/util"
1918

19+
"github.com/google/uuid"
20+
2021
"github.com/schollz/progressbar/v3"
2122
"github.com/spf13/cobra"
2223
"gopkg.in/yaml.v3"
@@ -36,6 +37,7 @@ var (
3637
configFile string
3738
allRuns bool
3839
numberOfRuns int
40+
runID string
3941
)
4042

4143
// OutputCmd represents the download command
@@ -117,17 +119,27 @@ The YAML config file should be formatted like:
117119
if allRuns {
118120
numberOfRuns = math.MaxInt
119121
}
120-
wfRuns := GetRuns(workflow.ID, numberOfRuns)
121-
if wfRuns != nil && len(wfRuns) > 0 {
122-
runs = append(runs, wfRuns...)
122+
if runID == "" {
123+
wfRuns := GetRuns(workflow.ID, numberOfRuns)
124+
if wfRuns != nil && len(wfRuns) > 0 {
125+
runs = append(runs, wfRuns...)
126+
} else {
127+
fmt.Println("This workflow has not been executed yet!")
128+
return
129+
}
123130
} else {
124-
fmt.Println("This workflow has not been executed yet!")
125-
return
131+
runUUID, err := uuid.Parse(runID)
132+
if err != nil {
133+
fmt.Println("Invalid run ID")
134+
return
135+
}
136+
run := GetRunByID(runUUID)
137+
runs = []types.Run{*run}
126138
}
127139

128-
if numberOfRuns == 1 && (wfRuns[0].Status == "SCHEDULED" || wfRuns[0].CreationType == types.RunCreationScheduled) {
129-
wfRuns = GetRuns(workflow.ID, numberOfRuns+1)
130-
runs = append(runs, wfRuns...)
140+
if numberOfRuns == 1 && (runs[0].Status == "SCHEDULED" || runs[0].CreationType == types.RunCreationScheduled) {
141+
runs = GetRuns(workflow.ID, numberOfRuns+1)
142+
runs = append(runs, runs...)
131143
}
132144

133145
version := GetWorkflowVersionByID(runs[0].WorkflowVersionInfo)
@@ -148,6 +160,7 @@ func init() {
148160
OutputCmd.Flags().StringVar(&configFile, "config", "", "YAML file to determine which nodes output(s) should be downloaded")
149161
OutputCmd.Flags().BoolVar(&allRuns, "all", false, "Download output data for all runs")
150162
OutputCmd.Flags().IntVar(&numberOfRuns, "runs", 1, "Number of recent runs which outputs should be downloaded")
163+
OutputCmd.Flags().StringVar(&runID, "run", "", "Download output data of a specific run")
151164
}
152165

153166
func DownloadRunOutput(run *types.Run, nodes map[string]NodeInfo, version *types.WorkflowVersionDetailed, destinationPath string) {
@@ -443,6 +456,27 @@ func getSubJobOutput(savePath string, subJob *types.SubJob, fetchData bool) []ty
443456
return subJobOutputs.Results
444457
}
445458

459+
func GetRunByID(id uuid.UUID) *types.Run {
460+
resp := request.Trickest.Get().DoF("run/%s/", id)
461+
if resp == nil {
462+
fmt.Println("Error: Couldn't get run!")
463+
os.Exit(0)
464+
}
465+
466+
if resp.Status() != http.StatusOK {
467+
request.ProcessUnexpectedResponse(resp)
468+
}
469+
470+
var run types.Run
471+
err := json.Unmarshal(resp.Body(), &run)
472+
if err != nil {
473+
fmt.Println("Error unmarshalling run response!")
474+
return nil
475+
}
476+
477+
return &run
478+
}
479+
446480
func getSubJobs(runID uuid.UUID) []types.SubJob {
447481
if runID == uuid.Nil {
448482
fmt.Println("Couldn't list sub-jobs, no run ID parameter specified!")

0 commit comments

Comments
 (0)