forked from travis-ci/worker
/
step_update_state.go
48 lines (37 loc) · 1.11 KB
/
step_update_state.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
package worker
import (
"github.com/mitchellh/multistep"
"github.com/travis-ci/worker/backend"
"github.com/travis-ci/worker/context"
gocontext "golang.org/x/net/context"
)
type stepUpdateState struct{}
func (s *stepUpdateState) Run(state multistep.StateBag) multistep.StepAction {
buildJob := state.Get("buildJob").(Job)
ctx := state.Get("ctx").(gocontext.Context)
err := buildJob.Started()
if err != nil {
context.LoggerFromContext(ctx).WithField("err", err).Error("couldn't mark job as started")
}
return multistep.ActionContinue
}
func (s *stepUpdateState) Cleanup(state multistep.StateBag) {
buildJob := state.Get("buildJob").(Job)
ctx := state.Get("ctx").(gocontext.Context)
mresult, ok := state.GetOk("scriptResult")
if ok {
result := mresult.(*backend.RunResult)
var err error
switch result.ExitCode {
case 0:
err = buildJob.Finish(FinishStatePassed)
case 1:
err = buildJob.Finish(FinishStateFailed)
default:
err = buildJob.Finish(FinishStateErrored)
}
if err != nil {
context.LoggerFromContext(ctx).WithField("err", err).Error("couldn't mark job as finished")
}
}
}