Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions caddy/caddy.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ func init() {
}

type workerConfig struct {
// Name for the worker
Name string `json:"name,omitempty"`
// FileName sets the path to the worker script.
FileName string `json:"file_name,omitempty"`
// Num sets the number of workers to start.
Expand Down Expand Up @@ -99,7 +101,7 @@ func (f *FrankenPHPApp) Start() error {
frankenphp.WithMaxWaitTime(f.MaxWaitTime),
}
for _, w := range f.Workers {
opts = append(opts, frankenphp.WithWorkers(repl.ReplaceKnown(w.FileName, ""), w.Num, w.Env, w.Watch))
opts = append(opts, frankenphp.WithWorkers(w.Name, repl.ReplaceKnown(w.FileName, ""), w.Num, w.Env, w.Watch))
}

frankenphp.Shutdown()
Expand Down Expand Up @@ -234,6 +236,11 @@ func (f *FrankenPHPApp) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
for d.NextBlock(1) {
v := d.Val()
switch v {
case "name":
if !d.NextArg() {
return d.ArgErr()
}
wc.Name = d.Val()
case "file":
if !d.NextArg() {
return d.ArgErr()
Expand Down Expand Up @@ -267,17 +274,26 @@ func (f *FrankenPHPApp) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
wc.Watch = append(wc.Watch, d.Val())
}
default:
allowedDirectives := "file, num, env, watch"
allowedDirectives := "name, file, num, env, watch"
return wrongSubDirectiveError("worker", allowedDirectives, v)
}
}

if wc.FileName == "" {
return errors.New(`the "file" argument must be specified`)
}
if wc.FileName == "" {
return errors.New(`the "file" argument must be specified`)
}

if frankenphp.EmbeddedAppPath != "" && filepath.IsLocal(wc.FileName) {
wc.FileName = filepath.Join(frankenphp.EmbeddedAppPath, wc.FileName)
}

if frankenphp.EmbeddedAppPath != "" && filepath.IsLocal(wc.FileName) {
wc.FileName = filepath.Join(frankenphp.EmbeddedAppPath, wc.FileName)
if wc.Name == "" {
// let worker initialization validate if the FileName is valid or not
name, _ := fastabs.FastAbs(wc.FileName)
if name == "" {
name = wc.FileName
}
wc.Name = name
}

f.Workers = append(f.Workers, wc)
Expand Down
Loading