From 54962a43eb5f6ebc4b98da46994e7d22df5ff789 Mon Sep 17 00:00:00 2001 From: Dylan Tinianov Date: Wed, 13 Dec 2023 11:36:00 -0500 Subject: [PATCH] Extract common --- core/services/pipeline/models.go | 4 +++ core/services/vrf/delegate.go | 2 +- core/store/models/common.go | 43 ++------------------------------ 3 files changed, 7 insertions(+), 42 deletions(-) diff --git a/core/services/pipeline/models.go b/core/services/pipeline/models.go index 4c83a0a231a..2e1dbd3fd24 100644 --- a/core/services/pipeline/models.go +++ b/core/services/pipeline/models.go @@ -19,6 +19,10 @@ import ( type Spec = common.Spec +func SpecPipeline(s Spec) (*Pipeline, error) { + return Parse(s.DotDagSource) +} + type Run struct { ID int64 `json:"-"` PipelineSpecID int32 `json:"-"` diff --git a/core/services/vrf/delegate.go b/core/services/vrf/delegate.go index 03e40614a10..4c1acbe4663 100644 --- a/core/services/vrf/delegate.go +++ b/core/services/vrf/delegate.go @@ -76,7 +76,7 @@ func (d *Delegate) ServicesForSpec(jb job.Job) ([]job.ServiceCtx, error) { if jb.VRFSpec == nil || jb.PipelineSpec == nil { return nil, errors.Errorf("vrf.Delegate expects a VRFSpec and PipelineSpec to be present, got %+v", jb) } - pl, err := jb.PipelineSpec.Pipeline() + pl, err := pipeline.SpecPipeline(*jb.PipelineSpec) if err != nil { return nil, err } diff --git a/core/store/models/common.go b/core/store/models/common.go index 93cc708fe0b..b2d617d4a0d 100644 --- a/core/store/models/common.go +++ b/core/store/models/common.go @@ -17,6 +17,7 @@ import ( "github.com/tidwall/gjson" "go.uber.org/multierr" + "github.com/smartcontractkit/chainlink-common/pkg/utils" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils/big" ) @@ -311,7 +312,7 @@ func (d *Duration) UnmarshalText(input []byte) error { } // Interval represents a time.Duration stored as a Postgres interval type -type Interval time.Duration +type Interval = utils.Interval // NewInterval creates Interval for specified duration func NewInterval(d time.Duration) *Interval { @@ -320,46 +321,6 @@ func NewInterval(d time.Duration) *Interval { return i } -func (i Interval) Duration() time.Duration { - return time.Duration(i) -} - -// MarshalText implements the text.Marshaler interface. -func (i Interval) MarshalText() ([]byte, error) { - return []byte(time.Duration(i).String()), nil -} - -// UnmarshalText implements the text.Unmarshaler interface. -func (i *Interval) UnmarshalText(input []byte) error { - v, err := time.ParseDuration(string(input)) - if err != nil { - return err - } - *i = Interval(v) - return nil -} - -func (i *Interval) Scan(v interface{}) error { - if v == nil { - *i = Interval(time.Duration(0)) - return nil - } - asInt64, is := v.(int64) - if !is { - return errors.Errorf("models.Interval#Scan() wanted int64, got %T", v) - } - *i = Interval(time.Duration(asInt64) * time.Nanosecond) - return nil -} - -func (i Interval) Value() (driver.Value, error) { - return time.Duration(i).Nanoseconds(), nil -} - -func (i Interval) IsZero() bool { - return time.Duration(i) == time.Duration(0) -} - // SendEtherRequest represents a request to transfer ETH. type SendEtherRequest struct { DestinationAddress common.Address `json:"address"`