-
Notifications
You must be signed in to change notification settings - Fork 117
/
max_time_criterion.go
39 lines (28 loc) · 1006 Bytes
/
max_time_criterion.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
package terminator
import (
"fmt"
"time"
"github.com/golang/protobuf/ptypes/any"
terminatorv1 "github.com/lyft/clutch/backend/api/config/service/chaos/experimentation/terminator/v1"
"github.com/lyft/clutch/backend/service/chaos/experimentation/experimentstore"
)
type maxTimeTerminationCriterion struct {
maxTime time.Duration
}
func (m maxTimeTerminationCriterion) ShouldTerminate(experiment *experimentstore.Experiment) (string, error) {
startTime := experiment.Run.StartTime
if startTime.Add(m.maxTime).Before(time.Now()) {
return fmt.Sprintf("timed out (max duration %s)", m.maxTime), nil
}
return "", nil
}
type maxTimeTerminationFactory struct{}
func (maxTimeTerminationFactory) Create(cfg *any.Any) (TerminationCriterion, error) {
typedConfig := &terminatorv1.MaxTimeTerminationCriterion{}
err := cfg.UnmarshalTo(typedConfig)
if err != nil {
return nil, err
}
maxTime := typedConfig.MaxDuration.AsDuration()
return maxTimeTerminationCriterion{maxTime: maxTime}, nil
}