forked from evergreen-ci/evergreen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
interface.go
93 lines (72 loc) · 1.96 KB
/
interface.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package command
import (
"context"
"sync"
"time"
"github.com/evergreen-ci/evergreen/model"
"github.com/evergreen-ci/evergreen/rest/client"
)
// Command is an interface that defines a command
// A Command takes parameters as a map, and is executed after
// those parameters are parsed.
type Command interface {
// ParseParams takes a map of fields to values extracted from
// the project config and passes them to the command. Any
// errors parsing the information are returned.
ParseParams(params map[string]interface{}) error
// Execute runs the command using the agent's logger, communicator,
// task config, and a channel for interrupting long-running commands.
// Execute is called after ParseParams.
Execute(context.Context, client.Communicator, client.LoggerProducer, *model.TaskConfig) error
// A string name for the command
Name() string
// Type reports on or overrides the default command type
// (e.g. system or task.) The setter MUST NOT override a value
// if it has already been set.
Type() string
SetType(string)
DisplayName() string
SetDisplayName(string)
IdleTimeout() time.Duration
SetIdleTimeout(time.Duration)
}
// base contains a basic implementation of functionality that is
// common to all command implementations.
type base struct {
idleTimeout time.Duration
typeName string
displayName string
mu sync.RWMutex
}
func (b *base) Type() string {
b.mu.RLock()
defer b.mu.RUnlock()
return b.typeName
}
func (b *base) SetType(n string) {
b.mu.Lock()
defer b.mu.Unlock()
if b.typeName == "" {
b.typeName = n
}
}
func (b *base) DisplayName() string {
b.mu.RLock()
defer b.mu.RUnlock()
return b.displayName
}
func (b *base) SetDisplayName(n string) {
b.mu.Lock()
defer b.mu.Unlock()
b.displayName = n
}
func (b *base) SetIdleTimeout(d time.Duration) {
b.mu.Lock()
defer b.mu.Unlock()
b.idleTimeout = d
}
func (b *base) IdleTimeout() time.Duration {
b.mu.RLock()
defer b.mu.RUnlock()
return b.idleTimeout
}