diff options
Diffstat (limited to 'plugins/factory')
-rw-r--r-- | plugins/factory/app.go | 2 | ||||
-rw-r--r-- | plugins/factory/app_provider.go | 2 | ||||
-rw-r--r-- | plugins/factory/factory.go | 47 |
3 files changed, 24 insertions, 27 deletions
diff --git a/plugins/factory/app.go b/plugins/factory/app.go index e4002963..74d8d828 100644 --- a/plugins/factory/app.go +++ b/plugins/factory/app.go @@ -76,7 +76,7 @@ func (app *App) NewCmd(env Env) (func() *exec.Cmd, error) { } // todo ENV unused -func (app *App) NewFactory(env Env) (roadrunner.Factory, error) { +func (app *App) NewFactory() (roadrunner.Factory, error) { if app.cfg.Relay == "" || app.cfg.Relay == "pipes" { return roadrunner.NewPipeFactory(), nil } diff --git a/plugins/factory/app_provider.go b/plugins/factory/app_provider.go index 024c5bea..e13b267f 100644 --- a/plugins/factory/app_provider.go +++ b/plugins/factory/app_provider.go @@ -13,5 +13,5 @@ type Spawner interface { NewCmd(env Env) (func() *exec.Cmd, error) // NewFactory inits new factory for workers. - NewFactory(env Env) (roadrunner.Factory, error) + NewFactory() (roadrunner.Factory, error) } diff --git a/plugins/factory/factory.go b/plugins/factory/factory.go index 5d80682d..f7303b6d 100644 --- a/plugins/factory/factory.go +++ b/plugins/factory/factory.go @@ -16,22 +16,34 @@ type WorkerFactory interface { } type WFactory struct { - spw Spawner - eb *events.EventBroadcaster + events *events.EventBroadcaster + app Spawner + wFactory roadrunner.Factory } -func (wf *WFactory) NewWorkerPool(ctx context.Context, opt *roadrunner.Config, env Env) (roadrunner.Pool, error) { - cmd, err := wf.spw.NewCmd(env) +func (wf *WFactory) Init(app Spawner) (err error) { + wf.events = events.NewEventBroadcaster() + + wf.app = app + wf.wFactory, err = app.NewFactory() if err != nil { - return nil, err + return nil } - factory, err := wf.spw.NewFactory(env) + return nil +} + +func (wf *WFactory) AddListener(l events.EventListener) { + wf.events.AddListener(l) +} + +func (wf *WFactory) NewWorkerPool(ctx context.Context, opt *roadrunner.Config, env Env) (roadrunner.Pool, error) { + cmd, err := wf.app.NewCmd(env) if err != nil { return nil, err } - p, err := roadrunner.NewPool(ctx, cmd, factory, opt) + p, err := roadrunner.NewPool(ctx, cmd, wf.wFactory, opt) if err != nil { return nil, err } @@ -39,7 +51,7 @@ func (wf *WFactory) NewWorkerPool(ctx context.Context, opt *roadrunner.Config, e // TODO event to stop go func() { for e := range p.Events() { - wf.eb.Push(e) + wf.events.Push(e) if we, ok := e.Payload.(roadrunner.WorkerEvent); ok { if we.Event == roadrunner.EventWorkerLog { log.Print(color.YellowString(string(we.Payload.([]byte)))) @@ -52,25 +64,10 @@ func (wf *WFactory) NewWorkerPool(ctx context.Context, opt *roadrunner.Config, e } func (wf *WFactory) NewWorker(ctx context.Context, env Env) (roadrunner.WorkerBase, error) { - cmd, err := wf.spw.NewCmd(env) + cmd, err := wf.app.NewCmd(env) if err != nil { return nil, err } - wb, err := roadrunner.InitBaseWorker(cmd()) - if err != nil { - return nil, err - } - - return wb, nil -} - -func (wf *WFactory) Init(app Spawner) error { - wf.spw = app - wf.eb = events.NewEventBroadcaster() - return nil -} - -func (wf *WFactory) AddListener(l events.EventListener) { - wf.eb.AddListener(l) + return wf.wFactory.SpawnWorkerWithContext(ctx, cmd()) } |