job

package
v1.10.17 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 18, 2021 License: MIT Imports: 33 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoSuchPeerID             = errors.New("no such peer id exists")
	ErrNoSuchKeyBundle          = errors.New("no such key bundle exists")
	ErrNoSuchTransmitterAddress = errors.New("no such transmitter address exists")
	ErrNoSuchPublicKey          = errors.New("no such public key exists")
)
View Source
var (
	ErrNoPipelineSpec       = errors.New("pipeline spec not specified")
	ErrInvalidJobType       = errors.New("invalid job type")
	ErrInvalidSchemaVersion = errors.New("invalid schema version")
)
View Source
var (
	ErrViolatesForeignKeyConstraint = errors.New("violates foreign key constraint")
)

Functions

func ExternalJobIDEncodeBytesToTopic added in v1.10.17

func ExternalJobIDEncodeBytesToTopic(id uuid.UUID) common.Hash

func ExternalJobIDEncodeStringToTopic added in v1.10.17

func ExternalJobIDEncodeStringToTopic(id uuid.UUID) common.Hash

func NewORM

func NewORM(
	db *gorm.DB,
	chainSet evm.ChainSet,
	pipelineORM pipeline.ORM,
	keyStore keystore.Master,
	lggr logger.Logger,
) *orm

func NewSpawner

func NewSpawner(orm ORM, config Config, jobTypeDelegates map[Type]Delegate, txm postgres.TransactionManager) *spawner

func PreloadAllJobTypes

func PreloadAllJobTypes(db *gorm.DB) *gorm.DB

Types

type Config

type Config interface {
	DatabaseMaximumTxDuration() time.Duration
	DatabaseURL() url.URL
	TriggerFallbackDBPollInterval() time.Duration
}

type CronSpec

type CronSpec struct {
	ID           int32     `toml:"-" gorm:"primary_key"`
	CronSchedule string    `toml:"schedule"`
	CreatedAt    time.Time `toml:"-"`
	UpdatedAt    time.Time `toml:"-"`
}

func (*CronSpec) BeforeCreate

func (s *CronSpec) BeforeCreate(db *gorm.DB) error

func (*CronSpec) BeforeSave

func (s *CronSpec) BeforeSave(db *gorm.DB) error

func (CronSpec) GetID

func (s CronSpec) GetID() string

func (*CronSpec) SetID

func (s *CronSpec) SetID(value string) error

func (CronSpec) TableName

func (CronSpec) TableName() string

type Delegate

type Delegate interface {
	JobType() Type
	// ServicesForSpec returns services to be started and stopped for this
	// job. In case a given job type relies upon well-defined startup/shutdown
	// ordering for services, they are started in the order they are given
	// and stopped in reverse order.
	ServicesForSpec(spec Job) ([]Service, error)
	AfterJobCreated(spec Job)
	BeforeJobDeleted(spec Job)
}

TODO(spook): I can't wait for Go generics

type DirectRequestSpec

type DirectRequestSpec struct {
	ID                       int32                    `toml:"-" gorm:"primary_key"`
	ContractAddress          ethkey.EIP55Address      `toml:"contractAddress"`
	MinIncomingConfirmations clnull.Uint32            `toml:"minIncomingConfirmations"`
	Requesters               models.AddressCollection `toml:"requesters"`
	MinContractPayment       *assets.Link             `toml:"minContractPaymentLinkJuels"`
	EVMChainID               *utils.Big               `toml:"evmChainID" gorm:"column:evm_chain_id"`
	CreatedAt                time.Time                `toml:"-"`
	UpdatedAt                time.Time                `toml:"-"`
}

func (DirectRequestSpec) TableName

func (DirectRequestSpec) TableName() string

type ExternalInitiatorWebhookSpec

type ExternalInitiatorWebhookSpec struct {
	ExternalInitiatorID int64
	ExternalInitiator   bridges.ExternalInitiator `gorm:"foreignkey:ExternalInitiatorID;->"`
	WebhookSpecID       int32
	WebhookSpec         WebhookSpec `gorm:"foreignkey:WebhookSpecID;->"`
	Spec                models.JSON
}

type FluxMonitorSpec

type FluxMonitorSpec struct {
	ID              int32               `toml:"-" gorm:"primary_key"`
	ContractAddress ethkey.EIP55Address `toml:"contractAddress"`
	Threshold       float32             `toml:"threshold,float"`
	// AbsoluteThreshold is the maximum absolute change allowed in a fluxmonitored
	// value before a new round should be kicked off, so that the current value
	// can be reported on-chain.
	AbsoluteThreshold   float32 `toml:"absoluteThreshold,float" gorm:"type:float;not null"`
	PollTimerPeriod     time.Duration
	PollTimerDisabled   bool
	IdleTimerPeriod     time.Duration
	IdleTimerDisabled   bool
	DrumbeatSchedule    string
	DrumbeatRandomDelay time.Duration
	DrumbeatEnabled     bool
	MinPayment          *assets.Link
	EVMChainID          *utils.Big `toml:"evmChainID" gorm:"column:evm_chain_id"`
	CreatedAt           time.Time  `toml:"-"`
	UpdatedAt           time.Time  `toml:"-"`
}

type FluxMonitorSpecIntThreshold added in v1.10.17

type FluxMonitorSpecIntThreshold struct {
	ContractAddress     ethkey.EIP55Address `toml:"contractAddress"`
	Threshold           int                 `toml:"threshold"`
	AbsoluteThreshold   int                 `toml:"absoluteThreshold"`
	PollTimerPeriod     time.Duration
	PollTimerDisabled   bool
	IdleTimerPeriod     time.Duration
	IdleTimerDisabled   bool
	DrumbeatSchedule    string
	DrumbeatRandomDelay time.Duration
	DrumbeatEnabled     bool
	MinPayment          *assets.Link
}

Need to also try integer thresholds until https://github.com/pelletier/go-toml/issues/571 is addressed. The UI's TOML.stringify({"threshold": 1.0}) (https://github.com/iarna/iarna-toml) will return "threshold = 1" since ts/js doesn't know the difference between 1.0 and 1, so we need to address it on the backend.

type Job

type Job struct {
	ID                            int32     `toml:"-" gorm:"primary_key"`
	ExternalJobID                 uuid.UUID `toml:"externalJobID"`
	OffchainreportingOracleSpecID *int32
	OffchainreportingOracleSpec   *OffchainReportingOracleSpec
	CronSpecID                    *int32
	CronSpec                      *CronSpec
	DirectRequestSpecID           *int32
	DirectRequestSpec             *DirectRequestSpec
	FluxMonitorSpecID             *int32
	FluxMonitorSpec               *FluxMonitorSpec
	KeeperSpecID                  *int32
	KeeperSpec                    *KeeperSpec
	VRFSpecID                     *int32
	VRFSpec                       *VRFSpec
	WebhookSpecID                 *int32
	WebhookSpec                   *WebhookSpec
	PipelineSpecID                int32
	PipelineSpec                  *pipeline.Spec
	JobSpecErrors                 []SpecError `gorm:"foreignKey:JobID"`
	Type                          Type
	SchemaVersion                 uint32
	Name                          null.String
	MaxTaskDuration               models.Interval
	Pipeline                      pipeline.Pipeline `toml:"observationSource" gorm:"-"`
}

func (Job) ExternalIDEncodeBytesToTopic

func (j Job) ExternalIDEncodeBytesToTopic() common.Hash

The external job ID (UUID) can also be encoded into a log topic (32 bytes) by taking the 16 bytes undelying the UUID and right padding it.

func (Job) ExternalIDEncodeStringToTopic

func (j Job) ExternalIDEncodeStringToTopic() common.Hash

The external job ID (UUID) can be encoded into a log topic (32 bytes) by taking the string representation of the UUID, removing the dashes so that its 32 characters long and then encoding those characters to bytes.

func (*Job) SetID

func (j *Job) SetID(value string) error

SetID takes the id as a string and attempts to convert it to an int32. If it succeeds, it will set it as the id on the job

func (Job) TableName

func (j Job) TableName() string

type KeeperSpec

type KeeperSpec struct {
	ID              int32               `toml:"-" gorm:"primary_key"`
	ContractAddress ethkey.EIP55Address `toml:"contractAddress"`
	FromAddress     ethkey.EIP55Address `toml:"fromAddress"`
	EVMChainID      *utils.Big          `toml:"evmChainID" gorm:"column:evm_chain_id"`
	CreatedAt       time.Time           `toml:"-"`
	UpdatedAt       time.Time           `toml:"-"`
}

type NullDelegate

type NullDelegate struct {
	Type Type
}

func (*NullDelegate) AfterJobCreated

func (*NullDelegate) AfterJobCreated(spec Job)

func (*NullDelegate) BeforeJobDeleted

func (*NullDelegate) BeforeJobDeleted(spec Job)

func (*NullDelegate) JobType

func (n *NullDelegate) JobType() Type

func (*NullDelegate) ServicesForSpec

func (n *NullDelegate) ServicesForSpec(spec Job) (s []Service, err error)

type OCRSpecConfig added in v1.10.17

type OCRSpecConfig interface {
	OCRBlockchainTimeout() time.Duration
	OCRContractConfirmations() uint16
	OCRContractPollInterval() time.Duration
	OCRContractSubscribeInterval() time.Duration
	OCRObservationTimeout() time.Duration
}

type ORM

type ORM interface {
	CreateJob(ctx context.Context, jobSpec *Job, pipeline pipeline.Pipeline) (Job, error)
	JobsV2(offset, limit int) ([]Job, int, error)
	FindJobTx(id int32) (Job, error)
	FindJob(ctx context.Context, id int32) (Job, error)
	FindJobByExternalJobID(ctx context.Context, uuid uuid.UUID) (Job, error)
	FindJobIDsWithBridge(name string) ([]int32, error)
	DeleteJob(ctx context.Context, id int32) error
	RecordError(ctx context.Context, jobID int32, description string)
	DismissError(ctx context.Context, errorID int32) error
	Close() error
	PipelineRuns(offset, size int) ([]pipeline.Run, int, error)
	PipelineRunsByJobID(jobID int32, offset, size int) ([]pipeline.Run, int, error)
}

type OffchainReportingOracleSpec

type OffchainReportingOracleSpec struct {
	ID                                     int32                `toml:"-" gorm:"primary_key"`
	ContractAddress                        ethkey.EIP55Address  `toml:"contractAddress"`
	P2PPeerID                              *p2pkey.PeerID       `toml:"p2pPeerID" gorm:"column:p2p_peer_id;default:null"`
	P2PBootstrapPeers                      pq.StringArray       `toml:"p2pBootstrapPeers" gorm:"column:p2p_bootstrap_peers;type:text[]"`
	IsBootstrapPeer                        bool                 `toml:"isBootstrapPeer"`
	EncryptedOCRKeyBundleID                *models.Sha256Hash   `toml:"keyBundleID" gorm:"type:bytea"`
	TransmitterAddress                     *ethkey.EIP55Address `toml:"transmitterAddress"`
	ObservationTimeout                     models.Interval      `toml:"observationTimeout" gorm:"type:bigint;default:null"`
	BlockchainTimeout                      models.Interval      `toml:"blockchainTimeout" gorm:"type:bigint;default:null"`
	ContractConfigTrackerSubscribeInterval models.Interval      `toml:"contractConfigTrackerSubscribeInterval" gorm:"default:null"`
	ContractConfigTrackerPollInterval      models.Interval      `toml:"contractConfigTrackerPollInterval" gorm:"type:bigint;default:null"`
	ContractConfigConfirmations            uint16               `toml:"contractConfigConfirmations"`
	EVMChainID                             *utils.Big           `toml:"evmChainID" gorm:"column:evm_chain_id"`
	CreatedAt                              time.Time            `toml:"-"`
	UpdatedAt                              time.Time            `toml:"-"`
}

TODO: remove pointers when upgrading to gormv2 which has https://github.com/go-gorm/gorm/issues/2748 fixed.

func LoadDynamicConfigVars added in v1.10.17

func (*OffchainReportingOracleSpec) BeforeCreate

func (s *OffchainReportingOracleSpec) BeforeCreate(db *gorm.DB) error

func (*OffchainReportingOracleSpec) BeforeSave

func (s *OffchainReportingOracleSpec) BeforeSave(db *gorm.DB) error

func (OffchainReportingOracleSpec) GetID

func (*OffchainReportingOracleSpec) SetID

func (s *OffchainReportingOracleSpec) SetID(value string) error

func (OffchainReportingOracleSpec) TableName

func (OffchainReportingOracleSpec) TableName() string

type PipelineRun

type PipelineRun struct {
	ID int64 `json:"-" gorm:"primary_key"`
}

func (PipelineRun) GetID

func (pr PipelineRun) GetID() string

func (*PipelineRun) SetID

func (pr *PipelineRun) SetID(value string) error

type Service

type Service interface {
	Start() error
	Close() error
}

type Spawner

type Spawner interface {
	service.Service
	CreateJob(ctx context.Context, spec Job, name null.String) (Job, error)
	DeleteJob(ctx context.Context, jobID int32) error
	ActiveJobs() map[int32]Job

	// NOTE: Prefer to use CreateJob, this is only publicly exposed for use in tests
	// to start a job that was previously manually inserted into DB
	StartService(spec Job) error
}

The job spawner manages the spinning up and spinning down of the long-running services that perform the work described by job specs. Each active job spec has 1 or more of these services associated with it.

type SpecError

type SpecError struct {
	ID          int64 `gorm:"primary_key"`
	JobID       int32
	Description string
	Occurrences uint
	CreatedAt   time.Time
	UpdatedAt   time.Time
}

func (SpecError) TableName

func (SpecError) TableName() string

type Type

type Type string
const (
	Cron              Type = "cron"
	DirectRequest     Type = "directrequest"
	FluxMonitor       Type = "fluxmonitor"
	OffchainReporting Type = "offchainreporting"
	Keeper            Type = "keeper"
	VRF               Type = "vrf"
	Webhook           Type = "webhook"
)

func ValidateSpec

func ValidateSpec(ts string) (Type, error)

ValidateSpec is the common spec validation

func (Type) RequiresPipelineSpec

func (t Type) RequiresPipelineSpec() bool

func (Type) SchemaVersion added in v1.10.17

func (t Type) SchemaVersion() uint32

func (Type) String

func (t Type) String() string

func (Type) SupportsAsync

func (t Type) SupportsAsync() bool

type VRFSpec

type VRFSpec struct {
	ID                 int32
	CoordinatorAddress ethkey.EIP55Address `toml:"coordinatorAddress"`
	PublicKey          secp256k1.PublicKey `toml:"publicKey"`
	Confirmations      uint32              `toml:"confirmations"`
	EVMChainID         *utils.Big          `toml:"evmChainID" gorm:"column:evm_chain_id"`
	CreatedAt          time.Time           `toml:"-"`
	UpdatedAt          time.Time           `toml:"-"`
}

type WebhookSpec

type WebhookSpec struct {
	ID                            int32 `toml:"-" gorm:"primary_key"`
	ExternalInitiatorWebhookSpecs []ExternalInitiatorWebhookSpec
	CreatedAt                     time.Time `json:"createdAt" toml:"-"`
	UpdatedAt                     time.Time `json:"updatedAt" toml:"-"`
}

func (WebhookSpec) GetID

func (w WebhookSpec) GetID() string

func (*WebhookSpec) SetID

func (w *WebhookSpec) SetID(value string) error

func (WebhookSpec) TableName

func (WebhookSpec) TableName() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL