@@ -45,6 +45,8 @@ func init() {
4545}
4646
4747type workerConfig struct {
48+ // Name for the worker
49+ Name string `json:"name,omitempty"`
4850 // FileName sets the path to the worker script.
4951 FileName string `json:"file_name,omitempty"`
5052 // Num sets the number of workers to start.
@@ -99,7 +101,7 @@ func (f *FrankenPHPApp) Start() error {
99101 frankenphp .WithMaxWaitTime (f .MaxWaitTime ),
100102 }
101103 for _ , w := range f .Workers {
102- opts = append (opts , frankenphp .WithWorkers (repl .ReplaceKnown (w .FileName , "" ), w .Num , w .Env , w .Watch ))
104+ opts = append (opts , frankenphp .WithWorkers (w . Name , repl .ReplaceKnown (w .FileName , "" ), w .Num , w .Env , w .Watch ))
103105 }
104106
105107 frankenphp .Shutdown ()
@@ -234,6 +236,11 @@ func (f *FrankenPHPApp) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
234236 for d .NextBlock (1 ) {
235237 v := d .Val ()
236238 switch v {
239+ case "name" :
240+ if ! d .NextArg () {
241+ return d .ArgErr ()
242+ }
243+ wc .Name = d .Val ()
237244 case "file" :
238245 if ! d .NextArg () {
239246 return d .ArgErr ()
@@ -267,17 +274,26 @@ func (f *FrankenPHPApp) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
267274 wc .Watch = append (wc .Watch , d .Val ())
268275 }
269276 default :
270- allowedDirectives := "file, num, env, watch"
277+ allowedDirectives := "name, file, num, env, watch"
271278 return wrongSubDirectiveError ("worker" , allowedDirectives , v )
272279 }
280+ }
273281
274- if wc .FileName == "" {
275- return errors .New (`the "file" argument must be specified` )
276- }
282+ if wc .FileName == "" {
283+ return errors .New (`the "file" argument must be specified` )
284+ }
285+
286+ if frankenphp .EmbeddedAppPath != "" && filepath .IsLocal (wc .FileName ) {
287+ wc .FileName = filepath .Join (frankenphp .EmbeddedAppPath , wc .FileName )
288+ }
277289
278- if frankenphp .EmbeddedAppPath != "" && filepath .IsLocal (wc .FileName ) {
279- wc .FileName = filepath .Join (frankenphp .EmbeddedAppPath , wc .FileName )
290+ if wc .Name == "" {
291+ // let worker initialization validate if the FileName is valid or not
292+ name , _ := fastabs .FastAbs (wc .FileName )
293+ if name == "" {
294+ name = wc .FileName
280295 }
296+ wc .Name = name
281297 }
282298
283299 f .Workers = append (f .Workers , wc )
0 commit comments