summaryrefslogtreecommitdiff
path: root/plugins/factory/factory.go
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2020-10-13 13:55:20 +0300
committerValery Piashchynski <[email protected]>2020-10-13 13:55:20 +0300
commit0dc44d54cfcc9dd3fa09a41136f35a9a8d26b994 (patch)
treeffcb65010bebe9f5b5436192979e64b2402a6ec0 /plugins/factory/factory.go
parent08d6b6b7f773f83b286cd48c1a0fbec9a62fb42b (diff)
Initial commit of RR 2.0v2.0.0-alpha1
Diffstat (limited to 'plugins/factory/factory.go')
-rw-r--r--plugins/factory/factory.go67
1 files changed, 67 insertions, 0 deletions
diff --git a/plugins/factory/factory.go b/plugins/factory/factory.go
new file mode 100644
index 00000000..74fd241f
--- /dev/null
+++ b/plugins/factory/factory.go
@@ -0,0 +1,67 @@
+package factory
+
+import (
+ "context"
+ "github.com/temporalio/roadrunner-temporal/events"
+
+ "github.com/temporalio/roadrunner-temporal/roadrunner"
+)
+
+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)
+ }
+ }()
+
+ 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)
+}