-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstage.go
52 lines (44 loc) · 1.06 KB
/
stage.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
package migration
import (
"context"
"time"
"github.com/rs/zerolog/log"
)
type Stage interface {
Name() StageName
Success() Step
Failure() Step
Execute(ctx context.Context, task *Task) bool
}
type stage struct {
name StageName
success Step
failure Step
execute Executor
}
func (s *stage) Name() StageName {
return s.name
}
func (s *stage) Success() Step {
return s.success
}
func (s *stage) Failure() Step {
return s.failure
}
// Execute stage and return changes and whether to stop execution
func (s *stage) Execute(ctx context.Context, task *Task) bool {
start := time.Now()
task.LastStep = s.Success()
err := s.execute(ctx, task)
if err != nil {
task.Status = StatusFailed
task.LastStep = s.Failure()
errorDetails := err.Error()
task.ErrorDetails = &errorDetails
log.Error().Str("module", "github.com/estafette/migration").Err(err).Str("taskID", task.ID).Str("stage", string(s.Name())).Msg("stage failed")
return false
}
// in update query duration is appended to existing value
task.TotalDuration += time.Since(start)
return true
}