mirror of
https://github.com/dunglas/frankenphp.git
synced 2025-12-24 13:38:11 +08:00
test
This commit is contained in:
@@ -38,12 +38,14 @@ type workerConfig struct {
|
||||
MatchPath []string `json:"match_path,omitempty"`
|
||||
// MaxConsecutiveFailures sets the maximum number of consecutive failures before panicking (defaults to 6, set to -1 to never panick)
|
||||
MaxConsecutiveFailures int `json:"max_consecutive_failures,omitempty"`
|
||||
// IsHTTPWorker specifies if the worker handles HTTP requests
|
||||
IsHTTPWorker bool `json:"http,omitempty"`
|
||||
|
||||
requestOptions []frankenphp.RequestOption
|
||||
}
|
||||
|
||||
func parseWorkerConfig(d *caddyfile.Dispenser) (workerConfig, error) {
|
||||
wc := workerConfig{}
|
||||
wc := workerConfig{IsHTTPWorker:true}
|
||||
if d.NextArg() {
|
||||
wc.FileName = d.Val()
|
||||
}
|
||||
@@ -116,6 +118,18 @@ func parseWorkerConfig(d *caddyfile.Dispenser) (workerConfig, error) {
|
||||
} else {
|
||||
wc.Watch = append(wc.Watch, d.Val())
|
||||
}
|
||||
case "http":
|
||||
if !d.NextArg() {
|
||||
wc.HTTP = true
|
||||
}
|
||||
v, err := strconv.ParseBool(d.Val())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if d.NextArg() {
|
||||
return d.ArgErr()
|
||||
}
|
||||
wc.HTTP = v
|
||||
case "match":
|
||||
// provision the path so it's identical to Caddy match rules
|
||||
// see: https://github.com/caddyserver/caddy/blob/master/modules/caddyhttp/matchers.go
|
||||
|
||||
12
options.go
12
options.go
@@ -44,6 +44,7 @@ type workerOpt struct {
|
||||
onThreadShutdown func(int)
|
||||
onServerStartup func()
|
||||
onServerShutdown func()
|
||||
isHTTP bool
|
||||
}
|
||||
|
||||
// WithContext sets the main context to use.
|
||||
@@ -90,6 +91,7 @@ func WithWorkers(name, fileName string, num int, options ...WorkerOption) Option
|
||||
env: PrepareEnv(nil),
|
||||
watch: []string{},
|
||||
maxConsecutiveFailures: defaultMaxConsecutiveFailures,
|
||||
isHTTP: true
|
||||
}
|
||||
|
||||
for _, option := range options {
|
||||
@@ -234,6 +236,16 @@ func WithWorkerOnServerShutdown(f func()) WorkerOption {
|
||||
}
|
||||
}
|
||||
|
||||
// AsHTTPWorker determines if the worker will handle HTTP requests (true by default).
|
||||
func AsHTTPWorker(isHTTP bool) WorkerOption {
|
||||
return func(w *workerOpt) error {
|
||||
w.isHTTP = isHTTP
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func withExtensionWorkers(w *extensionWorkers) WorkerOption {
|
||||
return func(wo *workerOpt) error {
|
||||
wo.extensionWorkers = w
|
||||
|
||||
@@ -31,6 +31,7 @@ type worker struct {
|
||||
onThreadReady func(int)
|
||||
onThreadShutdown func(int)
|
||||
queuedRequests atomic.Int32
|
||||
isHTTP bool
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -140,6 +141,7 @@ func newWorker(o workerOpt) (*worker, error) {
|
||||
maxConsecutiveFailures: o.maxConsecutiveFailures,
|
||||
onThreadReady: o.onThreadReady,
|
||||
onThreadShutdown: o.onThreadShutdown,
|
||||
isHTTP o.isHTTP
|
||||
}
|
||||
|
||||
w.requestOptions = append(
|
||||
|
||||
Reference in New Issue
Block a user