-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
common.go
53 lines (42 loc) · 1.07 KB
/
common.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
package job
import (
"context"
"net/url"
"github.com/smartcontractkit/chainlink/v2/core/services/pg"
)
//go:generate mockery --quiet --name ServiceCtx --output ./mocks/ --case=underscore
type Service interface {
Start() error
Close() error
}
// ServiceCtx is the same as Service, but Start method receives a context.
type ServiceCtx interface {
Start(context.Context) error
Close() error
}
type Config interface {
URL() url.URL
pg.QConfig
}
// ServiceAdapter is a helper introduced for transitioning from Service to ServiceCtx.
type ServiceAdapter interface {
ServiceCtx
}
type adapter struct {
service Service
}
// NewServiceAdapter creates an adapter instance for the given Service.
func NewServiceAdapter(service Service) ServiceCtx {
return &adapter{
service,
}
}
// Start forwards the call to the underlying service.Start().
// Context is not used in this case.
func (a adapter) Start(context.Context) error {
return a.service.Start()
}
// Close forwards the call to the underlying service.Close().
func (a adapter) Close() error {
return a.service.Close()
}