-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
delegate.go
47 lines (37 loc) · 1.34 KB
/
delegate.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
package cron
import (
"github.com/pkg/errors"
"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink/v2/core/services/job"
"github.com/smartcontractkit/chainlink/v2/core/services/pg"
"github.com/smartcontractkit/chainlink/v2/core/services/pipeline"
)
type Delegate struct {
pipelineRunner pipeline.Runner
lggr logger.Logger
}
var _ job.Delegate = (*Delegate)(nil)
func NewDelegate(pipelineRunner pipeline.Runner, lggr logger.Logger) *Delegate {
return &Delegate{
pipelineRunner: pipelineRunner,
lggr: lggr,
}
}
func (d *Delegate) JobType() job.Type {
return job.Cron
}
func (d *Delegate) BeforeJobCreated(spec job.Job) {}
func (d *Delegate) AfterJobCreated(spec job.Job) {}
func (d *Delegate) BeforeJobDeleted(spec job.Job) {}
func (d *Delegate) OnDeleteJob(spec job.Job, q pg.Queryer) error { return nil }
// ServicesForSpec returns the scheduler to be used for running cron jobs
func (d *Delegate) ServicesForSpec(spec job.Job) (services []job.ServiceCtx, err error) {
if spec.CronSpec == nil {
return nil, errors.Errorf("services.Delegate expects a *jobSpec.CronSpec to be present, got %v", spec)
}
cron, err := NewCronFromJobSpec(spec, d.pipelineRunner, d.lggr)
if err != nil {
return nil, err
}
return []job.ServiceCtx{cron}, nil
}