summaryrefslogtreecommitdiff
path: root/plugins/factory/factory.go
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/factory/factory.go')
-rw-r--r--plugins/factory/factory.go47
1 files changed, 22 insertions, 25 deletions
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())
}