-
Notifications
You must be signed in to change notification settings - Fork 1
/
executor.go
71 lines (58 loc) · 1.39 KB
/
executor.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
package common
import (
log "github.com/Sirupsen/logrus"
)
type ExecutorData interface{}
type ExecutorCommand struct {
Script string
Predefined bool
Abort chan interface{}
}
type Executor interface {
Shell() *ShellScriptInfo
Prepare(globalConfig *Config, config *RunnerConfig, build *Build) error
Run(cmd ExecutorCommand) error
Finish(err error)
Cleanup()
}
type ExecutorProvider interface {
CanCreate() bool
Create() Executor
Acquire(config *RunnerConfig) (ExecutorData, error)
Release(config *RunnerConfig, data ExecutorData) error
GetFeatures(features *FeaturesInfo)
}
var executors map[string]ExecutorProvider
func RegisterExecutor(executor string, provider ExecutorProvider) {
log.Debugln("Registering", executor, "executor...")
if executors == nil {
executors = make(map[string]ExecutorProvider)
}
if _, ok := executors[executor]; ok {
panic("Executor already exist: " + executor)
}
executors[executor] = provider
}
func GetExecutor(executor string) ExecutorProvider {
if executors == nil {
return nil
}
provider, _ := executors[executor]
return provider
}
func GetExecutors() []string {
names := []string{}
if executors != nil {
for name := range executors {
names = append(names, name)
}
}
return names
}
func NewExecutor(executor string) Executor {
provider := GetExecutor(executor)
if provider != nil {
return provider.Create()
}
return nil
}