-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.go
More file actions
146 lines (110 loc) · 3.92 KB
/
config.go
File metadata and controls
146 lines (110 loc) · 3.92 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package velox
import (
"fmt"
"time"
rrerrors "github.com/roadrunner-server/errors"
)
// Config holds the plugin configuration
type Config struct {
// ServerURL is the Velox build server base URL (required)
// The build endpoint path will be appended automatically
ServerURL string `mapstructure:"server_url"`
// BuildTimeout is the maximum time to wait for build completion (default: 5m)
BuildTimeout time.Duration `mapstructure:"build_timeout"`
// RequestTimeout is the HTTP request timeout for Velox communication (default: 180s)
RequestTimeout time.Duration `mapstructure:"request_timeout"`
// Retry configuration for Velox server communication
Retry RetryConfig `mapstructure:"retry"`
// Cache configuration for binary caching
Cache CacheConfig `mapstructure:"cache"`
}
// RetryConfig holds retry configuration
type RetryConfig struct {
// MaxAttempts is the maximum number of retry attempts (default: 3)
MaxAttempts int `mapstructure:"max_attempts"`
// InitialDelay is the initial delay before first retry (default: 1s)
InitialDelay time.Duration `mapstructure:"initial_delay"`
// MaxDelay is the maximum delay between retries (default: 10s)
MaxDelay time.Duration `mapstructure:"max_delay"`
// BackoffMultiplier is the backoff multiplier for exponential backoff (default: 2.0)
BackoffMultiplier float64 `mapstructure:"backoff_multiplier"`
}
// InitDefaults sets default values for the configuration
func (c *Config) InitDefaults() {
if c.BuildTimeout == 0 {
c.BuildTimeout = 5 * time.Minute
}
if c.RequestTimeout == 0 {
c.RequestTimeout = 180 * time.Second
}
if c.Retry.MaxAttempts == 0 {
c.Retry.MaxAttempts = 3
}
if c.Retry.InitialDelay == 0 {
c.Retry.InitialDelay = 1 * time.Second
}
if c.Retry.MaxDelay == 0 {
c.Retry.MaxDelay = 10 * time.Second
}
if c.Retry.BackoffMultiplier == 0 {
c.Retry.BackoffMultiplier = 2.0
}
// Initialize cache defaults
c.Cache.InitDefaults()
}
// Validate validates the configuration
func (c *Config) Validate() error {
const op = rrerrors.Op("velox_config_validate")
if c.ServerURL == "" {
return rrerrors.E(op, fmt.Errorf("server_url is required"))
}
if c.BuildTimeout < time.Second {
return rrerrors.E(op, fmt.Errorf("build_timeout must be at least 1 second"))
}
if c.RequestTimeout < time.Second {
return rrerrors.E(op, fmt.Errorf("request_timeout must be at least 1 second"))
}
if c.Retry.MaxAttempts < 1 {
return rrerrors.E(op, fmt.Errorf("retry.max_attempts must be at least 1"))
}
if c.Retry.InitialDelay < 0 {
return rrerrors.E(op, fmt.Errorf("retry.initial_delay cannot be negative"))
}
if c.Retry.MaxDelay < c.Retry.InitialDelay {
return rrerrors.E(op, fmt.Errorf("retry.max_delay must be greater than or equal to initial_delay"))
}
if c.Retry.BackoffMultiplier < 1.0 {
return rrerrors.E(op, fmt.Errorf("retry.backoff_multiplier must be at least 1.0"))
}
return nil
}
// BuildRequest represents the build request from PHP
type BuildRequest struct {
// RequestID is a unique identifier for the build request
RequestID string `json:"request_id"`
// TargetPlatform specifies the target OS and architecture
TargetPlatform Platform `json:"target_platform"`
// RRVersion is the RoadRunner version to build
RRVersion string `json:"rr_version"`
// Plugins is the list of plugins to include in the build
Plugins []BuildPlugin `json:"plugins"`
}
// Platform represents the target platform
type Platform struct {
// OS is the target operating system (windows, linux, darwin)
OS string `json:"os"`
// Arch is the target architecture (amd64, arm64)
Arch string `json:"arch"`
}
// BuildPlugin represents a RoadRunner plugin in the build request
type BuildPlugin struct {
// ModuleName is the full Go module path
ModuleName string `json:"module_name"`
// Tag is the Git tag or version
Tag string `json:"tag"`
}
// VeloxResponse represents the response from Velox server
type VeloxResponse struct {
Path string `json:"path"`
Logs string `json:"logs"`
}