/
job_exec.go
54 lines (40 loc) · 1.18 KB
/
job_exec.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
53
54
package core
import (
"context"
"fmt"
"github.com/otiai10/daap"
)
// Exec executes user-defined script inside the workflow container.
func (job *Job) Exec() error {
ctx := context.Background()
workflow := job.toWorkflowExecution()
stream, err := job.Container.Workflow.Exec(ctx, workflow)
if err != nil {
return err
}
for payload := range stream {
job.Stdio(payload.Type, EXECUTE, string(payload.Data))
}
if workflow.ExitCode != 0 {
return fmt.Errorf("script exited with %d, check verbose log", workflow.ExitCode)
}
return nil
}
func (job *Job) toWorkflowExecution() *daap.Execution {
env := []string{fmt.Sprintf("%s=%s", "HOTSUB_ROOT", HotsubContainerRoot)}
for _, e := range job.Container.Envs {
env = append(env, e.Pair())
}
workflow := &daap.Execution{Inspect: true, Env: env}
switch job.Type {
case CommonWorkflowLanguageJob:
// TODO: support more options for CWL
workflow.Inline = "cwltool ${CWL_FILE} ${CWL_JOB_FILE}"
case WorkflowDescriptionLanguageJob:
// TODO: support more options for WDL
workflow.Inline = "java -jar /cromwell-34.jar run ${WDL_FILE} -i ${WDL_JOB_FILE}"
default:
workflow.Script = job.Container.Script.Path
}
return workflow
}