/
cycle.go
73 lines (59 loc) · 1.86 KB
/
cycle.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
// Copyright (c) 2020-2021 C4 Project
//
// This file is part of c4t.
// Licenced under the MIT licence; see `LICENSE`.
package director
import (
"context"
"fmt"
"time"
"github.com/c4-project/c4t/internal/id"
"github.com/c4-project/c4t/internal/plan"
)
// cycleInstance contains state for one cycle of one instance of the director.
type cycleInstance struct {
// cycle contains information about which cycle this is.
cycle Cycle
// p points to the plan being built in this cycle.
p *plan.Plan
// stages contains the stages to run in this cycle.
stages []plan.Runner
}
func (c *cycleInstance) run(ctx context.Context) error {
for _, s := range c.stages {
if err := c.runStage(ctx, s); err != nil {
return err
}
}
return nil
}
func (c *cycleInstance) runStage(ctx context.Context, s plan.Runner) error {
var err error
if c.p, err = c.p.RunStage(ctx, s); err != nil {
return fmt.Errorf("in %s stage: %w", s.Stage(), err)
}
return nil
}
// Cycle contains information about a particular test cycle.
type Cycle struct {
// Instance is the index of the instance running this cycle.
// Indices currently start from 0, so the zero value is also a valid instance number; this may change.
Instance int `json:"instance"`
// MachineID is the ID of the machine on which this cycle is running.
MachineID id.ID `json:"machine_id,omitempty"`
// Iter is the iteration number of this cycle.
// Iteration numbers currently start from 0, so the zero value is also a valid iteration number; this may change.
Iter uint64 `json:"iter"`
// Start is the start time of this cycle.
Start time.Time `json:"start_time,omitempty"`
}
// String returns a string containing the components of this cycle in a human-readable manner.
func (r Cycle) String() string {
return fmt.Sprintf(
"[%d: %s #%d (%s)]",
r.Instance,
r.MachineID.String(),
r.Iter,
r.Start.Format(time.Stamp),
)
}