summaryrefslogtreecommitdiff
path: root/plugins/factory
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/factory')
-rw-r--r--plugins/factory/app.go39
-rw-r--r--plugins/factory/factory.go10
-rw-r--r--plugins/factory/tests/factory_test.go1
-rw-r--r--plugins/factory/tests/plugin_1.go4
4 files changed, 29 insertions, 25 deletions
diff --git a/plugins/factory/app.go b/plugins/factory/app.go
index f9e7944c..753ca2a9 100644
--- a/plugins/factory/app.go
+++ b/plugins/factory/app.go
@@ -1,7 +1,6 @@
package factory
import (
- "context"
"errors"
"fmt"
"os"
@@ -21,11 +20,10 @@ type AppConfig struct {
Group string
Env Env
- Relay string
// Listen defines connection method and factory to be used to connect to workers:
// "pipes", "tcp://:6001", "unix://rr.sock"
// This config section must not change on re-configuration.
- Listen string
+ Relay string
// RelayTimeout defines for how long socket factory will be waiting for worker connection. This config section
// must not change on re-configuration.
@@ -33,23 +31,28 @@ type AppConfig struct {
}
type App struct {
- cfg *AppConfig
+ cfg AppConfig
configProvider config.Provider
factory roadrunner.Factory
}
func (app *App) Init(provider config.Provider) error {
- app.cfg = &AppConfig{}
+ app.cfg = AppConfig{}
app.configProvider = provider
return nil
}
func (app *App) Configure() error {
- err := app.configProvider.UnmarshalKey("app", app.cfg)
+ err := app.configProvider.UnmarshalKey("app", &app.cfg)
if err != nil {
return err
}
+
+ if app.cfg.Relay == "" {
+ app.cfg.Relay = "pipes"
+ }
+
return nil
}
@@ -83,30 +86,28 @@ func (app *App) NewCmd(env Env) (func() *exec.Cmd, error) {
// todo ENV unused
func (app *App) NewFactory(env Env) (roadrunner.Factory, error) {
- // if Listen is empty or doesn't contain separator, return error
- if app.cfg.Listen == "" || !strings.Contains(app.cfg.Listen, "://") {
- return nil, errors.New("relay should be set")
- }
-
- lsn, err := util.CreateListener(app.cfg.Listen)
- if err != nil {
- return nil, err
+ if app.cfg.Relay == "" || app.cfg.Relay == "pipes" {
+ return roadrunner.NewPipeFactory(), nil
}
- dsn := strings.Split(app.cfg.Listen, "://")
+ dsn := strings.Split(app.cfg.Relay, "://")
if len(dsn) != 2 {
return nil, errors.New("invalid DSN (tcp://:6001, unix://file.sock)")
}
+ lsn, err := util.CreateListener(app.cfg.Relay)
+ if err != nil {
+ return nil, err
+ }
+
switch dsn[0] {
// sockets group
case "unix":
return roadrunner.NewSocketServer(lsn, app.cfg.RelayTimeout), nil
case "tcp":
return roadrunner.NewSocketServer(lsn, app.cfg.RelayTimeout), nil
- // pipes
default:
- return roadrunner.NewPipeFactory(), nil
+ return nil, errors.New("invalid DSN (tcp://:6001, unix://file.sock)")
}
}
@@ -116,10 +117,6 @@ func (app *App) Serve() chan error {
}
func (app *App) Stop() error {
- err := app.factory.Close(context.Background())
- if err != nil {
- return err
- }
return nil
}
diff --git a/plugins/factory/factory.go b/plugins/factory/factory.go
index c5490cd6..5d80682d 100644
--- a/plugins/factory/factory.go
+++ b/plugins/factory/factory.go
@@ -3,9 +3,11 @@ package factory
import (
"context"
- "github.com/spiral/roadrunner/v2/plugins/events"
+ "log"
+ "github.com/fatih/color"
"github.com/spiral/roadrunner/v2"
+ "github.com/spiral/roadrunner/v2/plugins/events"
)
type WorkerFactory interface {
@@ -23,6 +25,7 @@ func (wf *WFactory) NewWorkerPool(ctx context.Context, opt *roadrunner.Config, e
if err != nil {
return nil, err
}
+
factory, err := wf.spw.NewFactory(env)
if err != nil {
return nil, err
@@ -37,6 +40,11 @@ func (wf *WFactory) NewWorkerPool(ctx context.Context, opt *roadrunner.Config, e
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))))
+ }
+ }
}
}()
diff --git a/plugins/factory/tests/factory_test.go b/plugins/factory/tests/factory_test.go
index 38e939e1..72e28f84 100644
--- a/plugins/factory/tests/factory_test.go
+++ b/plugins/factory/tests/factory_test.go
@@ -46,7 +46,6 @@ func TestFactory(t *testing.T) {
t.Fatal(err)
}
-
err = container.Init()
if err != nil {
t.Fatal(err)
diff --git a/plugins/factory/tests/plugin_1.go b/plugins/factory/tests/plugin_1.go
index 0c44a0d1..5ab6df73 100644
--- a/plugins/factory/tests/plugin_1.go
+++ b/plugins/factory/tests/plugin_1.go
@@ -9,8 +9,8 @@ import (
)
type Foo struct {
- configProvider config.Provider
- spawner factory.Spawner
+ configProvider config.Provider
+ spawner factory.Spawner
}
func (f *Foo) Init(p config.Provider, spw factory.Spawner) error {