-
Notifications
You must be signed in to change notification settings - Fork 2
/
plugin.go
65 lines (53 loc) · 1.62 KB
/
plugin.go
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
package beanstalk
import (
"github.com/roadrunner-server/api/v4/plugins/v4/jobs"
"github.com/roadrunner-server/beanstalk/v5/beanstalkjobs"
"github.com/roadrunner-server/endure/v2/dep"
"github.com/roadrunner-server/errors"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
"go.uber.org/zap"
)
const pluginName string = "beanstalk"
type Configurer interface {
// UnmarshalKey takes a single key and unmarshal it into a Struct.
UnmarshalKey(name string, out any) error
// Has checks if a config section exists.
Has(name string) bool
}
type Logger interface {
NamedLogger(name string) *zap.Logger
}
type Tracer interface {
Tracer() *sdktrace.TracerProvider
}
type Plugin struct {
log *zap.Logger
cfg Configurer
tracer *sdktrace.TracerProvider
}
func (p *Plugin) Init(log Logger, cfg Configurer) error {
if !cfg.Has(pluginName) {
return errors.E(errors.Disabled)
}
p.log = log.NamedLogger(pluginName)
p.cfg = cfg
return nil
}
func (p *Plugin) Name() string {
return pluginName
}
func (p *Plugin) Collects() []*dep.In {
return []*dep.In{
dep.Fits(func(pp any) {
p.tracer = pp.(Tracer).Tracer()
}, (*Tracer)(nil)),
}
}
// DriverFromConfig constructs kafka driver from the .rr.yaml configuration
func (p *Plugin) DriverFromConfig(configKey string, pq jobs.Queue, pipeline jobs.Pipeline) (jobs.Driver, error) {
return beanstalkjobs.FromConfig(p.tracer, configKey, p.log, p.cfg, pipeline, pq)
}
// DriverFromPipeline constructs kafka driver from pipeline
func (p *Plugin) DriverFromPipeline(pipe jobs.Pipeline, pq jobs.Queue) (jobs.Driver, error) {
return beanstalkjobs.FromPipeline(p.tracer, pipe, p.log, p.cfg, pq)
}