Skip to content

Commit 947f85e

Browse files
fail plex jobs based on bacalhau status (#529)
Co-authored-by: Aakaash Meduri <aakaash.meduri@gmail.com>
1 parent b9f68eb commit 947f85e

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

internal/bacalhau/bacalhau.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,24 @@ func GetBacalhauJobResults(submittedJob *model.Job, showAnimation bool) (results
8686
fmt.Printf("Bacalhau job id: %s \n", submittedJob.Metadata.ID)
8787

8888
for i := 0; i < maxTrys; i++ {
89-
results, err = client.GetResults(context.Background(), submittedJob.Metadata.ID)
89+
updatedJob, _, err := client.Get(context.Background(), submittedJob.Metadata.ID)
9090
if err != nil {
9191
return results, err
9292
}
93-
if len(results) > 0 {
94-
return results, err
93+
if updatedJob.State.State == model.JobStateCancelled {
94+
return results, fmt.Errorf("bacalhau cancelled job; please run `bacalhau describe %s` for more details", submittedJob.Metadata.ID)
95+
} else if updatedJob.State.State == model.JobStateError {
96+
return results, fmt.Errorf("bacalhau errored job; please run `bacalhau describe %s` for more details", submittedJob.Metadata.ID)
97+
} else if updatedJob.State.State == model.JobStateCompleted {
98+
results, err = client.GetResults(context.Background(), submittedJob.Metadata.ID)
99+
if err != nil {
100+
return results, err
101+
}
102+
if len(results) > 0 {
103+
return results, err
104+
} else {
105+
return results, fmt.Errorf("bacalhau job completed but no results found")
106+
}
95107
}
96108
if showAnimation {
97109
saplingIndex := i % 5

0 commit comments

Comments
 (0)