Documentation ¶
Index ¶
- Constants
- Variables
- func NewPgxPool(ctx context.Context, url string) (*pgxpool.Pool, error)
- type Connection
- type FakePgxPoolWrapper
- func (p *FakePgxPoolWrapper) Acquire(_ context.Context) (Connection, error)
- func (p *FakePgxPoolWrapper) Begin(ctx context.Context) (pgx.Tx, error)
- func (p *FakePgxPoolWrapper) Close()
- func (p *FakePgxPoolWrapper) Conn() *pgx.Conn
- func (p *FakePgxPoolWrapper) Exec(ctx context.Context, sql string, arguments ...interface{}) (pgconn.CommandTag, error)
- func (p *FakePgxPoolWrapper) Query(ctx context.Context, sql string, args ...interface{}) (pgx.Rows, error)
- func (p *FakePgxPoolWrapper) QueryRow(ctx context.Context, sql string, args ...interface{}) pgx.Row
- func (p *FakePgxPoolWrapper) Release()
- type MockQueue
- func (_m *MockQueue) Cancel(ctx context.Context, taskId uuid.UUID) error
- func (_m *MockQueue) Dequeue(ctx context.Context, taskTypes []string) (*models.TaskInfo, error)
- func (_m *MockQueue) Enqueue(task *Task) (uuid.UUID, error)
- func (_m *MockQueue) Finish(taskId uuid.UUID, taskError error) error
- func (_m *MockQueue) Heartbeats(olderThan time.Duration) []uuid.UUID
- func (_m *MockQueue) IdFromToken(token uuid.UUID) (uuid.UUID, bool, error)
- func (_m *MockQueue) ListenForCancel(ctx context.Context, taskID uuid.UUID, cancelFunc context.CancelCauseFunc)
- func (_m *MockQueue) RefreshHeartbeat(token uuid.UUID) error
- func (_m *MockQueue) Requeue(taskId uuid.UUID) error
- func (_m *MockQueue) RequeueFailedTasks(taskTypes []string) error
- func (_m *MockQueue) Status(taskId uuid.UUID) (*models.TaskInfo, error)
- func (_m *MockQueue) UpdatePayload(task *models.TaskInfo, payload interface{}) (*models.TaskInfo, error)
- type PgQueue
- func (p *PgQueue) Cancel(ctx context.Context, taskId uuid.UUID) error
- func (p *PgQueue) Close()
- func (p *PgQueue) Dequeue(ctx context.Context, taskTypes []string) (*models.TaskInfo, error)
- func (p *PgQueue) Enqueue(task *Task) (uuid.UUID, error)
- func (p *PgQueue) Finish(taskId uuid.UUID, taskError error) error
- func (p *PgQueue) Heartbeats(olderThan time.Duration) []uuid.UUID
- func (p *PgQueue) IdFromToken(token uuid.UUID) (id uuid.UUID, isRunning bool, err error)
- func (p *PgQueue) ListenForCancel(ctx context.Context, taskID uuid.UUID, cancelFunc context.CancelCauseFunc)
- func (p *PgQueue) RefreshHeartbeat(token uuid.UUID) error
- func (p *PgQueue) RemoveAllTasks() error
- func (p *PgQueue) Requeue(taskId uuid.UUID) error
- func (p *PgQueue) RequeueFailedTasks(taskTypes []string) error
- func (p *PgQueue) Status(taskId uuid.UUID) (*models.TaskInfo, error)
- func (p *PgQueue) UpdatePayload(task *models.TaskInfo, payload interface{}) (*models.TaskInfo, error)
- type PgxConnWrapper
- func (p *PgxConnWrapper) Begin(ctx context.Context) (pgx.Tx, error)
- func (p *PgxConnWrapper) Conn() *pgx.Conn
- func (p *PgxConnWrapper) Exec(ctx context.Context, sql string, arguments ...interface{}) (pgconn.CommandTag, error)
- func (p *PgxConnWrapper) Query(ctx context.Context, sql string, args ...interface{}) (pgx.Rows, error)
- func (p *PgxConnWrapper) QueryRow(ctx context.Context, sql string, args ...interface{}) pgx.Row
- func (p *PgxConnWrapper) Release()
- type PgxPoolWrapper
- func (p *PgxPoolWrapper) Acquire(ctx context.Context) (Connection, error)
- func (p *PgxPoolWrapper) Begin(ctx context.Context) (pgx.Tx, error)
- func (p *PgxPoolWrapper) Close()
- func (p *PgxPoolWrapper) Exec(ctx context.Context, sql string, arguments ...interface{}) (pgconn.CommandTag, error)
- func (p *PgxPoolWrapper) Query(ctx context.Context, sql string, args ...interface{}) (pgx.Rows, error)
- func (p *PgxPoolWrapper) QueryRow(ctx context.Context, sql string, args ...interface{}) pgx.Row
- type Pool
- type Queue
- type Task
- type Transaction
Constants ¶
const MaxTaskRetries = 3 // Maximum number of times a task can be retried before failing
Variables ¶
var ( ErrNotExist = fmt.Errorf("task does not exist") ErrNotRunning = fmt.Errorf("task is not running") ErrTaskCanceled = fmt.Errorf("task was canceled") ErrContextCanceled = fmt.Errorf("dequeue context timed out or was canceled") ErrRowsNotAffected = fmt.Errorf("no rows were affected") ErrMaxRetriesExceeded = fmt.Errorf("task has exceeded the maximum amount of retries") ErrNotCancellable = fmt.Errorf("task not cancellable") )
Functions ¶
Types ¶
type Connection ¶
type Connection interface { Transaction Conn() *pgx.Conn Release() }
type FakePgxPoolWrapper ¶
type FakePgxPoolWrapper struct {
// contains filtered or unexported fields
}
FakePgxPoolWrapper is used for testing, to provide a pool interface implementation that doesn't actually use the pool in order to wrap all work in a transaction. This shouldn't be used in production, as it is based off a single transaction
func (*FakePgxPoolWrapper) Acquire ¶
func (p *FakePgxPoolWrapper) Acquire(_ context.Context) (Connection, error)
func (*FakePgxPoolWrapper) Begin ¶
func (p *FakePgxPoolWrapper) Begin(ctx context.Context) (pgx.Tx, error)
func (*FakePgxPoolWrapper) Close ¶
func (p *FakePgxPoolWrapper) Close()
func (*FakePgxPoolWrapper) Conn ¶
func (p *FakePgxPoolWrapper) Conn() *pgx.Conn
func (*FakePgxPoolWrapper) Exec ¶
func (p *FakePgxPoolWrapper) Exec(ctx context.Context, sql string, arguments ...interface{}) (pgconn.CommandTag, error)
func (*FakePgxPoolWrapper) Query ¶
func (p *FakePgxPoolWrapper) Query(ctx context.Context, sql string, args ...interface{}) (pgx.Rows, error)
func (*FakePgxPoolWrapper) QueryRow ¶
func (p *FakePgxPoolWrapper) QueryRow(ctx context.Context, sql string, args ...interface{}) pgx.Row
func (*FakePgxPoolWrapper) Release ¶
func (p *FakePgxPoolWrapper) Release()
type MockQueue ¶
MockQueue is an autogenerated mock type for the Queue type
func NewMockQueue ¶
NewMockQueue creates a new instance of MockQueue. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.
func (*MockQueue) Heartbeats ¶
Heartbeats provides a mock function with given fields: olderThan
func (*MockQueue) IdFromToken ¶
IdFromToken provides a mock function with given fields: token
func (*MockQueue) ListenForCancel ¶
func (_m *MockQueue) ListenForCancel(ctx context.Context, taskID uuid.UUID, cancelFunc context.CancelCauseFunc)
ListenForCancel provides a mock function with given fields: ctx, taskID, cancelFunc
func (*MockQueue) RefreshHeartbeat ¶
RefreshHeartbeat provides a mock function with given fields: token
func (*MockQueue) RequeueFailedTasks ¶
RequeueFailedTasks provides a mock function with given fields: taskTypes
type PgQueue ¶
type PgQueue struct { Pool Pool // contains filtered or unexported fields }
PgQueue a task queue backed by postgres, using pgxpool.Pool using a wrapper (PgxPoolWrapper) that implements a Pool interface
func (*PgQueue) IdFromToken ¶
func (*PgQueue) ListenForCancel ¶
func (*PgQueue) RefreshHeartbeat ¶
Reset the last heartbeat time to time.Now()
func (*PgQueue) RemoveAllTasks ¶
RemoveAllTasks used for tests, along with testTx, to clear tables before running tests
func (*PgQueue) RequeueFailedTasks ¶
type PgxConnWrapper ¶
type PgxConnWrapper struct {
// contains filtered or unexported fields
}
PgxConnWrapper wraps a pgxpool Conn in a generic interface to allow for alternative implementations, such as the FakePgxPoolWrapper
func (*PgxConnWrapper) Conn ¶
func (p *PgxConnWrapper) Conn() *pgx.Conn
func (*PgxConnWrapper) Exec ¶
func (p *PgxConnWrapper) Exec(ctx context.Context, sql string, arguments ...interface{}) (pgconn.CommandTag, error)
func (*PgxConnWrapper) Query ¶
func (p *PgxConnWrapper) Query(ctx context.Context, sql string, args ...interface{}) (pgx.Rows, error)
func (*PgxConnWrapper) QueryRow ¶
func (p *PgxConnWrapper) QueryRow(ctx context.Context, sql string, args ...interface{}) pgx.Row
func (*PgxConnWrapper) Release ¶
func (p *PgxConnWrapper) Release()
type PgxPoolWrapper ¶
type PgxPoolWrapper struct {
// contains filtered or unexported fields
}
PgxPoolWrapper wraps a pgx Pool in a generic interface to allow for alternative implementations, such as the FakePgxPoolWrapper
func (*PgxPoolWrapper) Acquire ¶
func (p *PgxPoolWrapper) Acquire(ctx context.Context) (Connection, error)
func (*PgxPoolWrapper) Close ¶
func (p *PgxPoolWrapper) Close()
func (*PgxPoolWrapper) Exec ¶
func (p *PgxPoolWrapper) Exec(ctx context.Context, sql string, arguments ...interface{}) (pgconn.CommandTag, error)
type Pool ¶
type Pool interface { Transaction Acquire(ctx context.Context) (Connection, error) Close() }
Pool matches the pgxpool.Pool struct
type Queue ¶
type Queue interface { // Enqueue Enqueues a job Enqueue(task *Task) (uuid.UUID, error) // Dequeue Dequeues a job of a type in taskTypes, blocking until one is available. Dequeue(ctx context.Context, taskTypes []string) (*models.TaskInfo, error) // Status returns Status of the given task Status(taskId uuid.UUID) (*models.TaskInfo, error) // Finish finishes given task, setting status to completed or failed if taskError is not nil Finish(taskId uuid.UUID, taskError error) error // Requeue requeues the given task Requeue(taskId uuid.UUID) error // Heartbeats returns the tokens of all tasks older than given duration Heartbeats(olderThan time.Duration) []uuid.UUID // IdFromToken returns a task's ID given its token IdFromToken(token uuid.UUID) (id uuid.UUID, isRunning bool, err error) // RefreshHeartbeat refresh heartbeat of task given its token RefreshHeartbeat(token uuid.UUID) error // UpdatePayload update the payload on a task UpdatePayload(task *models.TaskInfo, payload interface{}) (*models.TaskInfo, error) // ListenForCancel registers a channel and listens for notification for given task, then calls cancelFunc on receive. Should run as goroutine. ListenForCancel(ctx context.Context, taskID uuid.UUID, cancelFunc context.CancelCauseFunc) // Cancel sends notification to cancel given task and sets task state to canceled Cancel(ctx context.Context, taskId uuid.UUID) error // RequeueFailedTasks requeues all failed tasks of taskTypes to the queue RequeueFailedTasks(taskTypes []string) error }
type Transaction ¶
type Transaction interface { Begin(ctx context.Context) (pgx.Tx, error) Exec(ctx context.Context, sql string, arguments ...interface{}) (pgconn.CommandTag, error) Query(ctx context.Context, sql string, args ...interface{}) (pgx.Rows, error) QueryRow(ctx context.Context, sql string, args ...interface{}) pgx.Row }
Transaction mimics the pgx.Tx struct