summaryrefslogtreecommitdiff
path: root/plugins/factory/tests/plugin_2.go
blob: d0c3ea2c7e10dce28da72f31760075f94cf7736d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package tests

import (
	"context"
	"errors"
	"fmt"
	"time"

	"github.com/temporalio/roadrunner-temporal/config"
	"github.com/temporalio/roadrunner-temporal/factory"
	"github.com/temporalio/roadrunner-temporal/roadrunner"
)

type Foo2 struct {
	configProvider config.Provider
	wf             factory.WorkerFactory
	spw            factory.Spawner
}

func (f *Foo2) Init(p config.Provider, workerFactory factory.WorkerFactory, spawner factory.Spawner) error {
	f.configProvider = p
	f.wf = workerFactory
	f.spw = spawner
	return nil
}

func (f *Foo2) Serve() chan error {
	errCh := make(chan error, 1)

	r := &factory.AppConfig{}
	err := f.configProvider.UnmarshalKey("app", r)
	if err != nil {
		errCh <- err
		return errCh
	}

	cmd, err := f.spw.NewCmd(nil)
	if err != nil {
		errCh <- err
		return errCh
	}
	if cmd == nil {
		errCh <- errors.New("command is nil")
		return errCh
	}
	a := cmd()
	out, err := a.Output()
	if err != nil {
		errCh <- err
		return errCh
	}

	w, err := f.wf.NewWorker(context.Background(), nil)
	if err != nil {
		errCh <- err
		return errCh
	}

	_ = w

	poolConfig := &roadrunner.Config{
		NumWorkers:      10,
		MaxJobs:         100,
		AllocateTimeout: time.Second * 10,
		DestroyTimeout:  time.Second * 10,
		TTL:             1000,
		IdleTTL:         1000,
		ExecTTL:         time.Second * 10,
		MaxPoolMemory:   10000,
		MaxWorkerMemory: 10000,
	}

	pool, err := f.wf.NewWorkerPool(context.Background(), poolConfig, nil)
	if err != nil {
		errCh <- err
		return errCh
	}

	_ = pool

	fmt.Println(string(out))

	return errCh
}

func (f *Foo2) Stop() error {
	return nil
}