Documentation ¶
Index ¶
- Constants
- Variables
- func Batch(cb BatchFunc) error
- func DBWithDefaultContext(db *gorm.DB, fc func(db *gorm.DB) error) error
- func DefaultQueryCtx() (ctx context.Context, cancel context.CancelFunc)
- func GormTransaction(ctx context.Context, db *gorm.DB, fc func(tx *gorm.DB) error, ...) (err error)
- func GormTransactionWithDefaultContext(db *gorm.DB, fc func(tx *gorm.DB) error, txOptss ...sql.TxOptions) error
- func GormTransactionWithoutContext(db *gorm.DB, fc func(tx *gorm.DB) error, txOptss ...sql.TxOptions) (err error)
- func IsSerializationAnomaly(err error) bool
- func MustSQLDB(db *gorm.DB) *sql.DB
- func MustSQLTx(db *gorm.DB) *sql.Tx
- func NewEventBroadcaster(uri url.URL, minReconnectInterval time.Duration, ...) *eventBroadcaster
- func Sessions(db *gorm.DB, offset, limit int) ([]models.Session, error)
- func SqlTransaction(ctx context.Context, rdb *sql.DB, fc func(tx *sqlx.Tx) error, ...) (err error)
- func SqlxTransaction(ctx context.Context, q Queryer, fc func(tx *sqlx.Tx) error, ...) (err error)
- func TxFromContext(ctx context.Context, db *gorm.DB) *gorm.DB
- func UnwrapGormDB(db *gorm.DB) *sqlx.DB
- func WrapDbWithSqlx(rdb *sql.DB) *sqlx.DB
- type AdvisoryLocker
- type BatchFunc
- type Event
- type EventBroadcaster
- type NullAdvisoryLocker
- type NullEventBroadcaster
- func (*NullEventBroadcaster) Close() error
- func (*NullEventBroadcaster) Healthy() error
- func (*NullEventBroadcaster) Notify(channel string, payload string) error
- func (*NullEventBroadcaster) NotifyInsideGormTx(tx *gorm.DB, channel string, payload string) error
- func (*NullEventBroadcaster) Ready() error
- func (*NullEventBroadcaster) Start() error
- func (*NullEventBroadcaster) Subscribe(channel, payloadFilter string) (Subscription, error)
- type Queryer
- type Subscription
- type TransactionManager
- type TransactionOption
- type TxFn
Constants ¶
const ( AdvisoryLockClassID_EthBroadcaster int32 = 0 AdvisoryLockClassID_JobSpawner int32 = 1 AdvisoryLockClassID_EthConfirmer int32 = 2 // ORM takes lock on 1027321974924625846 which splits into ClassID 239192036, ObjID 2840971190 AdvisoryLockClassID_ORM int32 = 239192036 AdvisoryLockObjectID_EthConfirmer int32 = 0 )
NOTE: All advisory lock class IDs used by the Chainlink application MUST be kept here to avoid accidental re-use
const ( ChannelJobCreated = "insert_on_jobs" ChannelJobDeleted = "delete_from_jobs" ChannelRunStarted = "pipeline_run_started" ChannelRunCompleted = "pipeline_run_completed" // Postgres channel to listen for new eth_txes ChannelInsertOnEthTx = "insert_on_eth_txes" )
const ( // LockTimeout controls the max time we will wait for any kind of database lock. // It's good to set this to _something_ because waiting for locks forever is really bad. LockTimeout = 15 * time.Second // IdleInTxSessionTimeout controls the max time we leave a transaction open and idle. // It's good to set this to _something_ because leaving transactions open forever is really bad. IdleInTxSessionTimeout = 1 * time.Hour )
NOTE: In an ideal world the timeouts below would be set to something sane in the postgres configuration by the user. Since we do not live in an ideal world, it is necessary to override them here.
They cannot easily be set at a session level due to how Go's connection pooling works.
const BatchSize uint = 1000
BatchSize is the default number of DB records to access in one batch
const DefaultQueryTimeout = 10 * time.Second
Variables ¶
var ( DefaultSqlTxOptions = sql.TxOptions{ Isolation: sql.LevelReadCommitted, } )
var (
ErrNoDeadlineSet = errors.New("no deadline set")
)
Functions ¶
func DBWithDefaultContext ¶ added in v0.10.8
func DefaultQueryCtx ¶ added in v0.10.2
func DefaultQueryCtx() (ctx context.Context, cancel context.CancelFunc)
DefaultQueryCtx returns a context with a sensible sanity limit timeout for SQL queries
func GormTransaction ¶
func GormTransaction(ctx context.Context, db *gorm.DB, fc func(tx *gorm.DB) error, txOptss ...sql.TxOptions) (err error)
DEPRECATED: Use the transaction manager instead.
func GormTransactionWithDefaultContext ¶ added in v0.10.8
func GormTransactionWithDefaultContext(db *gorm.DB, fc func(tx *gorm.DB) error, txOptss ...sql.TxOptions) error
DEPRECATED: Use the transaction manager instead.
func GormTransactionWithoutContext ¶ added in v0.10.8
func GormTransactionWithoutContext(db *gorm.DB, fc func(tx *gorm.DB) error, txOptss ...sql.TxOptions) (err error)
WARNING: Only use for nested txes inside ORM methods where you expect db to already have a ctx with a deadline.
func IsSerializationAnomaly ¶
func MustSQLTx ¶ added in v0.10.8
MustSQLDB panics if there is an error getting the underlying SQL TX
func NewEventBroadcaster ¶
func SqlTransaction ¶ added in v1.0.0
func SqlxTransaction ¶ added in v0.10.10
func TxFromContext ¶ added in v0.10.11
TxFromContext extracts the tx from the context. If no transaction value is provided in the context, it returns the gorm.DB.
Types ¶
type AdvisoryLocker ¶
type AdvisoryLocker interface { Unlock(ctx context.Context, classID int32, objectID int32) error WithAdvisoryLock(ctx context.Context, classID int32, objectID int32, f func() error) error Close() error }
func NewAdvisoryLock ¶
func NewAdvisoryLock(uri url.URL) AdvisoryLocker
type BatchFunc ¶ added in v0.10.10
BatchFunc is the function to execute on each batch of records, should return the count of records affected
type EventBroadcaster ¶
type EventBroadcaster interface { service.Service Subscribe(channel, payloadFilter string) (Subscription, error) Notify(channel string, payload string) error NotifyInsideGormTx(tx *gorm.DB, channel string, payload string) error }
EventBroadcaster opaquely manages a collection of Postgres event listeners and broadcasts events to subscribers (with an optional payload filter).
type NullAdvisoryLocker ¶
type NullAdvisoryLocker struct {
// contains filtered or unexported fields
}
func (*NullAdvisoryLocker) Close ¶
func (n *NullAdvisoryLocker) Close() error
func (*NullAdvisoryLocker) WithAdvisoryLock ¶
type NullEventBroadcaster ¶ added in v0.10.8
type NullEventBroadcaster struct{}
NullEventBroadcaster implements null pattern for event broadcaster
func (*NullEventBroadcaster) Close ¶ added in v0.10.8
func (*NullEventBroadcaster) Close() error
func (*NullEventBroadcaster) Healthy ¶ added in v0.10.8
func (*NullEventBroadcaster) Healthy() error
func (*NullEventBroadcaster) Notify ¶ added in v0.10.8
func (*NullEventBroadcaster) Notify(channel string, payload string) error
func (*NullEventBroadcaster) NotifyInsideGormTx ¶ added in v0.10.8
func (*NullEventBroadcaster) Ready ¶ added in v0.10.8
func (*NullEventBroadcaster) Ready() error
func (*NullEventBroadcaster) Start ¶ added in v0.10.8
func (*NullEventBroadcaster) Start() error
func (*NullEventBroadcaster) Subscribe ¶ added in v0.10.8
func (*NullEventBroadcaster) Subscribe(channel, payloadFilter string) (Subscription, error)
type Queryer ¶ added in v1.0.0
type Queryer interface { sqlx.Ext sqlx.ExtContext QueryRow(query string, args ...interface{}) *sql.Row }
func UnwrapGorm ¶ added in v1.0.0
type Subscription ¶
type Subscription interface { Events() <-chan Event Close() ChannelName() string InterestedIn(event Event) bool Send(event Event) }
Subscription represents a subscription to a Postgres event channel
type TransactionManager ¶ added in v0.10.11
type TransactionManager interface { Transact(TxFn, ...TransactionOption) error TransactWithContext(ctx context.Context, fn TxFn, optsFn ...TransactionOption) (err error) }
func NewGormTransactionManager ¶ added in v0.10.11
func NewGormTransactionManager(db *gorm.DB) TransactionManager
type TransactionOption ¶ added in v0.10.11
type TransactionOption func(opts *transactionOptions)
TransactionManagerOption configures how we set up the transaction
func WithTxOptions ¶ added in v0.10.11
func WithTxOptions(txopts sql.TxOptions) TransactionOption
WithTxOptions returns a TransactionOption which sets the sql.TxOptions on the transaction.
func WithoutDeadline ¶ added in v0.10.11
func WithoutDeadline() TransactionOption