jobinator

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2018 License: MIT Imports: 7 Imported by: 0

README

jobinator

GoDocBuild Status Coverage Status Go Report Card FOSSA Status

a background processing library for go

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BackgroundWorker

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

BackgroundWorker represents a worker thread that runs in the background

func (*BackgroundWorker) IsRunning

func (bw *BackgroundWorker) IsRunning() bool

IsRunning returns whether or not the background worker is running.

func (*BackgroundWorker) Start

func (bw *BackgroundWorker) Start()

Start starts the background worker. If it is already running, nothing happens.

func (*BackgroundWorker) Stop

func (bw *BackgroundWorker) Stop()

Stop stops the background worker. This is non blocking, so it may take some time before the background worker is fully stopped. Use IsRunning() to see if it's still running.

func (*BackgroundWorker) StopBlocking

func (bw *BackgroundWorker) StopBlocking()

StopBlocking stops the background worker. It will block until the background worker has stopped running.

type CleanUpConfig

type CleanUpConfig struct {
	MaxAge        time.Duration
	IncludeFailed bool
}

CleanUpConfig includes options for CleanUp methods

type Client

type Client struct {
	InternalClient
	// contains filtered or unexported fields
}

Client is the main handle for a jobinator instance. It is where you will perform most actions.

func NewClient

func NewClient(ic InternalClient, config ClientConfig) *Client

NewClient will wrap a client implementation and return the resulting client. Meant to be used for implementing storage backends.

func (*Client) CleanUp

func (c *Client) CleanUp(config CleanUpConfig) error

CleanUp deletes all jobs that have been finished (or optionally failed jobs) older than specified in the CleanUpConfig

func (*Client) DestroyAllWorkers

func (c *Client) DestroyAllWorkers()

DestroyAllWorkers stops all workers registered with the client and destroys them.

func (*Client) EnqueueJob

func (c *Client) EnqueueJob(name string, args interface{}, config JobConfig) error

EnqueueJob queues up a job to be run by a worker.

func (*Client) NamedJobInfo

func (c *Client) NamedJobInfo(name string) (JobInfo, error)

func (*Client) NewBackgroundWorker

func (c *Client) NewBackgroundWorker() *BackgroundWorker

NewBackgroundWorker returns a background worker handle, as well as registers it in the client. You can either keep it to start it yourself or use the client to start all background worker threads.

func (*Client) PendingJobs

func (c *Client) PendingJobs() ([]*Job, error)

PendingJobs returns the number of pending jobs.

func (*Client) RegisterWorker

func (c *Client) RegisterWorker(name string, wf WorkerFunc)

RegisterWorker registers a new workerfunc against it's identifier(name)

func (*Client) StartAllWorkers

func (c *Client) StartAllWorkers()

StartAllWorkers starts all workers registered with the client.

func (*Client) StopAllWorkers

func (c *Client) StopAllWorkers()

StopAllWorkers stops all workers registered with the client. This is non blocking, so you may need to wait before they are all finished.

func (*Client) StopAllWorkersBlocking

func (c *Client) StopAllWorkersBlocking()

StopAllWorkersBlocking stops all workers registered with the client. This is blocking.

type ClientConfig

type ClientConfig struct {
	WorkerSleepTime time.Duration
}

ClientConfig is settings that the client uses during runtime

type InternalClient

type InternalClient interface {
	InternalEnqueueJob(*Job) error
	InternalSelectJob() (*Job, error)
	InternalPendingJobs() ([]*Job, error)
	InternalRegisterWorker(string, WorkerFunc)
	IncRetryCount(*Job) error
	SetStatus(*Job, int) error
	SetFinishedAt(*Job, int64) error
	SetNextRun(*Job, int64) error
	SetError(*Job, string, string) error
	InternalCleanup(CleanUpConfig) error
	GetNamedJob(string) (*Job, error)
}

InternalClient is the interface a storage backend has to implement. See memoryclient or gormclient for details.

type Job

type Job struct {
	ID             string
	Name           string `gorm:"index"`
	Args           []byte
	CreatedAt      int64
	Status         int `gorm:"index"`
	RetryCount     int
	MaxRetry       int
	Error          string
	ErrorStack     string
	FinishedAt     int64
	Repeat         bool
	RepeatInterval time.Duration
	NextRun        int64
	NamedJob       string `gorm:"index"` //named jobs should be unique but we don't want to require a name, so I'm not using unique_index
}

Job is the internal representation of a job

type JobConfig

type JobConfig struct {
	MaxRetry       int
	Repeat         bool
	RepeatInterval time.Duration
	Identifier     string
}

JobConfig includes options for when a job is queued

type JobInfo

type JobInfo struct {
	Identifier     string
	ID             string
	LastRun        time.Time
	NextRun        time.Time
	RepeatInterval time.Duration
	Repeat         bool
	Args           []byte
}

type JobRef

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

JobRef is a reference to a job (and it's client). It is passed to a WorkerFunc to get the job args

func (*JobRef) ScanArgs

func (j *JobRef) ScanArgs(v interface{}) error

ScanArgs scans the job's arguments into your struct of choice.

type WorkerFunc

type WorkerFunc func(j *JobRef) error

WorkerFunc is the type of function that must be implemented to be a worker

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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