forked from travis-ci/worker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
job.go
102 lines (84 loc) · 2.94 KB
/
job.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
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package worker
import (
"time"
gocontext "context"
"github.com/bitly/go-simplejson"
"github.com/travis-ci/worker/backend"
)
const (
VMTypeDefault = "default"
VMTypePremium = "premium"
)
var VMConfigDefault = backend.VmConfig{GpuCount: 0, GpuType: ""}
type jobPayloadStartAttrs struct {
Config *backend.StartAttributes `json:"config"`
VmConfig *backend.VmConfig `json:"vm_config"`
}
type httpJobPayloadStartAttrs struct {
Data *jobPayloadStartAttrs `json:"data"`
}
// JobPayload is the payload we receive over RabbitMQ.
type JobPayload struct {
Type string `json:"type"`
Job JobJobPayload `json:"job"`
Build BuildPayload `json:"source"`
Repository RepositoryPayload `json:"repository"`
UUID string `json:"uuid"`
Config map[string]interface{} `json:"config"`
Timeouts TimeoutsPayload `json:"timeouts,omitempty"`
VMType string `json:"vm_type"`
VMConfig backend.VmConfig `json:"vm_config"`
Meta JobMetaPayload `json:"meta"`
Trace bool `json:"trace"`
}
// JobMetaPayload contains meta information about the job.
type JobMetaPayload struct {
StateUpdateCount uint `json:"state_update_count"`
}
// JobJobPayload contains information about the job.
type JobJobPayload struct {
ID uint64 `json:"id"`
Number string `json:"number"`
QueuedAt *time.Time `json:"queued_at"`
}
// BuildPayload contains information about the build.
type BuildPayload struct {
ID uint64 `json:"id"`
Number string `json:"number"`
}
// RepositoryPayload contains information about the repository.
type RepositoryPayload struct {
ID uint64 `json:"id"`
Slug string `json:"slug"`
}
// TimeoutsPayload contains information about any custom timeouts. The timeouts
// are given in seconds, and a value of 0 means no custom timeout is set.
type TimeoutsPayload struct {
HardLimit uint64 `json:"hard_limit"`
LogSilence uint64 `json:"log_silence"`
}
// FinishState is the state that a job finished with (such as pass/fail/etc.).
// You should not provide a string directly, but use one of the FinishStateX
// constants defined in this package.
type FinishState string
// Valid finish states for the FinishState type
const (
FinishStatePassed FinishState = "passed"
FinishStateFailed FinishState = "failed"
FinishStateErrored FinishState = "errored"
FinishStateCancelled FinishState = "cancelled"
)
// A Job ties togeher all the elements required for a build job
type Job interface {
Payload() *JobPayload
RawPayload() *simplejson.Json
StartAttributes() *backend.StartAttributes
Received(gocontext.Context) error
Started(gocontext.Context) error
Error(gocontext.Context, string) error
Requeue(gocontext.Context) error
Finish(gocontext.Context, FinishState) error
LogWriter(gocontext.Context, time.Duration) (LogWriter, error)
Name() string
SetupContext(gocontext.Context) gocontext.Context
}