jobqueue

package module
v0.0.0-...-16a7d50 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2020 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DBRepository

type DBRepository struct {
	// contains filtered or unexported fields
}

DBRepository defines a MySQL-based repository

func (*DBRepository) AddJob

func (r *DBRepository) AddJob(job *Job) (*Job, error)

AddJob adds a job to the queue

func (*DBRepository) Process

func (r *DBRepository) Process(queue string, interval time.Duration, processors map[string]JobProcessor)

Process starts processing jobs from the given queue with the given interval

func (*DBRepository) Setup

func (r *DBRepository) Setup()

Setup is used to perform the setup of the repository

type Job

type Job struct {
	ID         int64  `db:"id"`
	Queue      string `db:"queue"`
	State      string `db:"state"`
	Error      string `db:"error"`
	Payload    string `db:"payload"`
	CreatedOn  int64  `db:"created_on"`
	StartedOn  int64  `db:"started_on"`
	FinishedOn int64  `db:"finished_on"`
}

Job defines a job which can be queued

func NewJob

func NewJob(queue string, payload JobPayload) (*Job, error)

NewJob returns a new job for the given queue with an optional payload

func (*Job) BoolArg

func (job *Job) BoolArg(name string) bool

BoolArg retrieves a bool argument from the payload

func (*Job) FloatArg

func (job *Job) FloatArg(name string) float64

FloatArg retrieves an integer argument from the payload

func (*Job) IntArg

func (job *Job) IntArg(name string) int64

IntArg retrieves an integer argument from the payload

func (*Job) StringArg

func (job *Job) StringArg(name string) string

StringArg retrieves a string argument from the payload

type JobPayload

type JobPayload map[string]interface{}

JobPayload is used to define the payload of a job

type JobProcessor

type JobProcessor interface {
	Process(job *Job) error
}

JobProcessor defines the interface for a job processor

type JobRepository

type JobRepository interface {
	Setup()
	AddJob(job *Job) (*Job, error)
	Process(queue string, interval time.Duration, processors map[string]JobProcessor)
}

JobRepository is the interface to which repositories should conform

func DefaultRepository

func DefaultRepository() (JobRepository, error)

DefaultRepository returns the default repository based on the env variables

func NewMySQLRepository

func NewMySQLRepository(db *sqlx.DB, tableName string) JobRepository

NewMySQLRepository returns a new MySQL-based repository

Directories

Path Synopsis
cmd
go-jobqueue command
scripts
post_build command
pre_build command

Jump to

Keyboard shortcuts

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