-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
estimator.go
33 lines (27 loc) · 905 Bytes
/
estimator.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
package estimation
import (
"strings"
wfv1 "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1"
)
// Estimator return estimations for how long workflows and nodes will take
type Estimator interface {
EstimateWorkflowDuration() wfv1.EstimatedDuration
EstimateNodeDuration(nodeName string) wfv1.EstimatedDuration
}
type estimator struct {
wf *wfv1.Workflow
baselineWF *wfv1.Workflow
}
func (e *estimator) EstimateWorkflowDuration() wfv1.EstimatedDuration {
if e.baselineWF == nil {
return 0
}
return wfv1.NewEstimatedDuration(e.baselineWF.Status.GetDuration())
}
func (e *estimator) EstimateNodeDuration(nodeName string) wfv1.EstimatedDuration {
if e.baselineWF == nil {
return 0
}
oldNodeID := e.baselineWF.NodeID(strings.Replace(nodeName, e.wf.Name, e.baselineWF.Name, 1))
return wfv1.NewEstimatedDuration(e.baselineWF.Status.Nodes[oldNodeID].GetDuration())
}