-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjob_factory.go
More file actions
84 lines (67 loc) · 1.7 KB
/
job_factory.go
File metadata and controls
84 lines (67 loc) · 1.7 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package worker
import (
"strings"
"github.com/google/uuid"
"github.com/hyp3rd/ewrap"
)
const (
jobMetaNameKey = "job.name"
jobMetaRepoKey = "job.repo"
jobMetaTagKey = "job.tag"
jobMetaSourceKey = "job.source"
jobMetaTarballURLKey = "job.tarball_url"
jobMetaTarballPathKey = "job.tarball_path"
jobMetaTarballSHAKey = "job.tarball_sha256"
jobMetaPathKey = "job.path"
jobMetaDockerfileKey = "job.dockerfile"
jobMetaCommandKey = "job.command"
jobMetaQueueKey = "job.queue"
)
func jobDurableTask(job AdminJob) (DurableTask, error) {
payload, err := JobPayloadFromSpec(job.AdminJobSpec)
if err != nil {
return DurableTask{}, err
}
task := DurableTask{
ID: uuid.New(),
Handler: JobHandlerName,
Message: payload,
Queue: strings.TrimSpace(job.Queue),
Retries: job.Retries,
}
task.Metadata = jobMetadata(job)
if task.Handler == "" {
return DurableTask{}, ewrap.New("job handler is required")
}
return task, nil
}
func jobMetadata(job AdminJob) map[string]string {
meta := map[string]string{
jobMetaNameKey: job.Name,
jobMetaRepoKey: job.Repo,
jobMetaTagKey: job.Tag,
jobMetaSourceKey: job.Source,
}
if job.TarballURL != "" {
meta[jobMetaTarballURLKey] = job.TarballURL
}
if job.TarballPath != "" {
meta[jobMetaTarballPathKey] = job.TarballPath
}
if job.TarballSHA != "" {
meta[jobMetaTarballSHAKey] = job.TarballSHA
}
if job.Path != "" {
meta[jobMetaPathKey] = job.Path
}
if job.Dockerfile != "" {
meta[jobMetaDockerfileKey] = job.Dockerfile
}
if len(job.Command) > 0 {
meta[jobMetaCommandKey] = strings.Join(job.Command, " ")
}
if job.Queue != "" {
meta[jobMetaQueueKey] = job.Queue
}
return meta
}