summaryrefslogtreecommitdiff
path: root/plugins/factory/factory.go
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2020-10-26 12:01:53 +0300
committerGitHub <[email protected]>2020-10-26 12:01:53 +0300
commit91cf918b30938129609323ded53e190385e019a6 (patch)
tree0ad9537bd438c63719fb83343ab77fc4ab34eb83 /plugins/factory/factory.go
parent68bf13772c6ddfc5159c2a286e1a38e911614e72 (diff)
parent9aae9e2009bad07ebdee73e1c6cf56901d07880a (diff)
Merge pull request #373 from spiral/feature/new-worker-produces-active-worker
Feature/new worker produces active worker
Diffstat (limited to 'plugins/factory/factory.go')
-rwxr-xr-xplugins/factory/factory.go76
1 files changed, 0 insertions, 76 deletions
diff --git a/plugins/factory/factory.go b/plugins/factory/factory.go
deleted file mode 100755
index 5d80682d..00000000
--- a/plugins/factory/factory.go
+++ /dev/null
@@ -1,76 +0,0 @@
-package factory
-
-import (
- "context"
-
- "log"
-
- "github.com/fatih/color"
- "github.com/spiral/roadrunner/v2"
- "github.com/spiral/roadrunner/v2/plugins/events"
-)
-
-type WorkerFactory interface {
- NewWorker(ctx context.Context, env Env) (roadrunner.WorkerBase, error)
- NewWorkerPool(ctx context.Context, opt *roadrunner.Config, env Env) (roadrunner.Pool, error)
-}
-
-type WFactory struct {
- spw Spawner
- eb *events.EventBroadcaster
-}
-
-func (wf *WFactory) NewWorkerPool(ctx context.Context, opt *roadrunner.Config, env Env) (roadrunner.Pool, error) {
- cmd, err := wf.spw.NewCmd(env)
- if err != nil {
- return nil, err
- }
-
- factory, err := wf.spw.NewFactory(env)
- if err != nil {
- return nil, err
- }
-
- p, err := roadrunner.NewPool(ctx, cmd, factory, opt)
- if err != nil {
- return nil, err
- }
-
- // TODO event to stop
- go func() {
- for e := range p.Events() {
- wf.eb.Push(e)
- if we, ok := e.Payload.(roadrunner.WorkerEvent); ok {
- if we.Event == roadrunner.EventWorkerLog {
- log.Print(color.YellowString(string(we.Payload.([]byte))))
- }
- }
- }
- }()
-
- return p, nil
-}
-
-func (wf *WFactory) NewWorker(ctx context.Context, env Env) (roadrunner.WorkerBase, error) {
- cmd, err := wf.spw.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)
-}