diff options
Diffstat (limited to 'plugins/app')
-rw-r--r-- | plugins/app/plugin.go (renamed from plugins/app/app.go) | 24 | ||||
-rw-r--r-- | plugins/app/tests/.rr.yaml | 2 | ||||
-rw-r--r-- | plugins/app/tests/factory_test.go | 16 | ||||
-rw-r--r-- | plugins/app/tests/hello.php | 20 | ||||
-rw-r--r-- | plugins/app/tests/plugin_1.go | 4 | ||||
-rw-r--r-- | plugins/app/tests/plugin_2.go | 4 |
6 files changed, 47 insertions, 23 deletions
diff --git a/plugins/app/app.go b/plugins/app/plugin.go index 312e5bc6..2ef851e8 100644 --- a/plugins/app/app.go +++ b/plugins/app/plugin.go @@ -26,15 +26,15 @@ type WorkerFactory interface { NewWorkerPool(ctx context.Context, opt roadrunner.Config, env Env) (roadrunner.Pool, error) } -// App manages worker -type App struct { +// Plugin manages worker +type Plugin struct { cfg Config log *zap.Logger factory roadrunner.Factory } // Init application provider. -func (app *App) Init(cfg config.Provider, log *zap.Logger) error { +func (app *Plugin) Init(cfg config.Configurer, log *zap.Logger) error { err := cfg.UnmarshalKey(ServiceName, &app.cfg) if err != nil { return err @@ -46,11 +46,11 @@ func (app *App) Init(cfg config.Provider, log *zap.Logger) error { } // Name contains service name. -func (app *App) Name() string { +func (app *Plugin) Name() string { return ServiceName } -func (app *App) Serve() chan error { +func (app *Plugin) Serve() chan error { errCh := make(chan error, 1) var err error @@ -62,7 +62,7 @@ func (app *App) Serve() chan error { return errCh } -func (app *App) Stop() error { +func (app *Plugin) Stop() error { if app.factory == nil { return nil } @@ -71,7 +71,7 @@ func (app *App) Stop() error { } // CmdFactory provides worker command factory assocated with given context. -func (app *App) CmdFactory(env Env) (func() *exec.Cmd, error) { +func (app *Plugin) CmdFactory(env Env) (func() *exec.Cmd, error) { var cmdArgs []string // create command according to the config @@ -97,7 +97,7 @@ func (app *App) CmdFactory(env Env) (func() *exec.Cmd, error) { } // NewWorker issues new standalone worker. -func (app *App) NewWorker(ctx context.Context, env Env) (roadrunner.WorkerBase, error) { +func (app *Plugin) NewWorker(ctx context.Context, env Env) (roadrunner.WorkerBase, error) { spawnCmd, err := app.CmdFactory(env) if err != nil { return nil, err @@ -114,7 +114,7 @@ func (app *App) NewWorker(ctx context.Context, env Env) (roadrunner.WorkerBase, } // NewWorkerPool issues new worker pool. -func (app *App) NewWorkerPool(ctx context.Context, opt roadrunner.Config, env Env) (roadrunner.Pool, error) { +func (app *Plugin) NewWorkerPool(ctx context.Context, opt roadrunner.Config, env Env) (roadrunner.Pool, error) { spawnCmd, err := app.CmdFactory(env) if err != nil { return nil, err @@ -131,7 +131,7 @@ func (app *App) NewWorkerPool(ctx context.Context, opt roadrunner.Config, env En } // creates relay and worker factory. -func (app *App) initFactory() (roadrunner.Factory, error) { +func (app *Plugin) initFactory() (roadrunner.Factory, error) { if app.cfg.Relay == "" || app.cfg.Relay == "pipes" { return roadrunner.NewPipeFactory(), nil } @@ -157,7 +157,7 @@ func (app *App) initFactory() (roadrunner.Factory, error) { } } -func (app *App) setEnv(e Env) []string { +func (app *Plugin) setEnv(e Env) []string { env := append(os.Environ(), fmt.Sprintf("RR_RELAY=%s", app.cfg.Relay)) for k, v := range e { env = append(env, fmt.Sprintf("%s=%s", strings.ToUpper(k), v)) @@ -166,7 +166,7 @@ func (app *App) setEnv(e Env) []string { return env } -func (app *App) collectLogs(event interface{}) { +func (app *Plugin) collectLogs(event interface{}) { if we, ok := event.(roadrunner.WorkerEvent); ok { switch we.Event { case roadrunner.EventWorkerError: diff --git a/plugins/app/tests/.rr.yaml b/plugins/app/tests/.rr.yaml index 171f51dc..c9d1bd40 100644 --- a/plugins/app/tests/.rr.yaml +++ b/plugins/app/tests/.rr.yaml @@ -1,5 +1,5 @@ app: - command: "php hello.php" + command: "php plugins/app/tests/hello.php hello_echo" user: "" group: "" env: diff --git a/plugins/app/tests/factory_test.go b/plugins/app/tests/factory_test.go index 7c885797..969c361c 100644 --- a/plugins/app/tests/factory_test.go +++ b/plugins/app/tests/factory_test.go @@ -9,24 +9,25 @@ import ( "github.com/spiral/endure" "github.com/spiral/roadrunner/v2/plugins/app" "github.com/spiral/roadrunner/v2/plugins/config" + "github.com/spiral/roadrunner/v2/plugins/logger" "github.com/stretchr/testify/assert" ) func TestFactory(t *testing.T) { - container, err := endure.NewContainer(endure.DebugLevel, endure.RetryOnFail(true)) + container, err := endure.NewContainer(nil, endure.RetryOnFail(true), endure.SetLogLevel(endure.DebugLevel)) if err != nil { t.Fatal(err) } // config plugin - vp := &config.ViperProvider{} - vp.Path = ".rr.yaml" + vp := &config.Viper{} + vp.Path = "plugins/app/tests/.rr.yaml" vp.Prefix = "rr" err = container.Register(vp) if err != nil { t.Fatal(err) } - err = container.Register(&app.App{}) + err = container.Register(&app.Plugin{}) if err != nil { t.Fatal(err) } @@ -41,6 +42,11 @@ func TestFactory(t *testing.T) { t.Fatal(err) } + err = container.Register(&logger.ZapLogger{}) + if err != nil { + t.Fatal(err) + } + err = container.Init() if err != nil { t.Fatal(err) @@ -55,7 +61,7 @@ func TestFactory(t *testing.T) { c := make(chan os.Signal, 1) signal.Notify(c, os.Interrupt) - tt := time.NewTicker(time.Second * 2) + tt := time.NewTicker(time.Second * 200) for { select { diff --git a/plugins/app/tests/hello.php b/plugins/app/tests/hello.php index bf9e82cc..4219dcf4 100644 --- a/plugins/app/tests/hello.php +++ b/plugins/app/tests/hello.php @@ -1 +1,19 @@ -<?php echo "hello1 - " . time();
\ No newline at end of file +<?php +/** + * @var Goridge\RelayInterface $relay + */ + +use Spiral\Goridge; +use Spiral\RoadRunner; + +require "/vendor_php/autoload.php"; + +$rr = new RoadRunner\Worker($relay); + +while ($in = $rr->receive($ctx)) { + try { + $rr->send((string)$in); + } catch (\Throwable $e) { + $rr->error((string)$e); + } +}
\ No newline at end of file diff --git a/plugins/app/tests/plugin_1.go b/plugins/app/tests/plugin_1.go index 7259ea9d..c6287f5c 100644 --- a/plugins/app/tests/plugin_1.go +++ b/plugins/app/tests/plugin_1.go @@ -9,11 +9,11 @@ import ( ) type Foo struct { - configProvider config.Provider + configProvider config.Configurer spawner app.WorkerFactory } -func (f *Foo) Init(p config.Provider, spw app.WorkerFactory) error { +func (f *Foo) Init(p config.Configurer, spw app.WorkerFactory) error { f.configProvider = p f.spawner = spw return nil diff --git a/plugins/app/tests/plugin_2.go b/plugins/app/tests/plugin_2.go index fbb9ca11..51fb83a4 100644 --- a/plugins/app/tests/plugin_2.go +++ b/plugins/app/tests/plugin_2.go @@ -12,11 +12,11 @@ import ( ) type Foo2 struct { - configProvider config.Provider + configProvider config.Configurer wf app.WorkerFactory } -func (f *Foo2) Init(p config.Provider, workerFactory app.WorkerFactory) error { +func (f *Foo2) Init(p config.Configurer, workerFactory app.WorkerFactory) error { f.configProvider = p f.wf = workerFactory return nil |