jobqueue

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2021 License: Apache-2.0 Imports: 7 Imported by: 24

Documentation

Index

Constants

View Source
const (
	// ResultStatusSuccess means that the job is successfully processed.
	ResultStatusSuccess = "success"

	// ResultStatusFailure means that the job is failed but it may be retried.
	ResultStatusFailure = "failure"

	// ResultStatusPermanentFailure means that the job is failed and
	// should never be retried.
	ResultStatusPermanentFailure = "permanent-failure"

	// ResultStatusInternalFailure means that the job is failed before
	// processing it in some internal reason.
	ResultStatusInternalFailure = "internal-failure"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ConnectionClosedError

type ConnectionClosedError struct{}

ConnectionClosedError is an error returned when Pop() is called but connection to a remote store has been lost.

func (*ConnectionClosedError) Error

func (e *ConnectionClosedError) Error() string

type FailedJob

type FailedJob struct {
	ID        uint64          `json:"id"`
	JobID     uint64          `json:"job_id"`
	Category  string          `json:"category"`
	URL       string          `json:"url"`
	Payload   json.RawMessage `json:"payload,omitempty"`
	Result    *Result         `json:"result"`
	FailCount uint            `json:"fail_count"`
	FailedAt  time.Time       `json:"failed_at"`
	CreatedAt time.Time       `json:"created_at"`
}

FailedJob describes a (permanently) failed job that was in a queue.

type FailedJobs

type FailedJobs struct {
	FailedJobs []FailedJob `json:"failed_jobs"`
	NextCursor string      `json:"next_cursor"`
}

FailedJobs describes a (page of) failed job list of a queue.

type FailureLog

type FailureLog interface {
	Add(failed Job, result *Result) error
	Delete(failureID uint64) error
	Find(failureID uint64) (*FailedJob, error)
	FindAll(limit uint, cursor string) (*FailedJobs, error)
	FindAllRecentFailures(limit uint, cursor string) (*FailedJobs, error)
}

FailureLog is an interface to inspect failed jobs of a queue.

type HasFailureLog

type HasFailureLog interface {
	FailureLog() FailureLog
}

HasFailureLog is an interface describing that it has an FailureLog.

This is typically a JobQueue sub-interface.

type HasInspector

type HasInspector interface {
	Inspector() Inspector
}

HasInspector is an interface describing that it has an Inspector.

This is typically a JobQueue sub-interface.

type HasNodeInfo

type HasNodeInfo interface {
	Node() (*Node, error)
}

HasNodeInfo is an interface describing that it has a Node information.

This is typically a JobQueue sub-interface.

type Impl

type Impl interface {
	Start()
	Stop() <-chan struct{}
	Push(job IncomingJob) (Job, error)
	Pop(limit uint) ([]Job, error)
	Delete(job Job)
	Update(job Job, next NextInfo)
	IsActive() bool
}

Impl is an interface of a job queue implementation.

type InactiveError

type InactiveError struct{}

InactiveError is an error returned when Pop() is called on an inactive queue.

func (*InactiveError) Error

func (e *InactiveError) Error() string

type IncomingJob

type IncomingJob interface {
	Category() string
	URL() string
	Payload() string

	NextDelay() uint64 // milliseconds
	Timeout() uint     // seconds
	RetryDelay() uint  // seconds
	RetryCount() uint
}

IncomingJob is an interface of incoming jobs.

type InspectedJob

type InspectedJob struct {
	ID         uint64          `json:"id"`
	Category   string          `json:"category"`
	URL        string          `json:"url"`
	Payload    json.RawMessage `json:"payload,omitempty"`
	Status     string          `json:"status"`
	CreatedAt  time.Time       `json:"created_at"`
	NextTry    time.Time       `json:"next_try"`
	Timeout    uint            `json:"timeout"`
	FailCount  uint            `json:"fail_count"`
	MaxRetries uint            `json:"max_retries"`
	RetryDelay uint            `json:"retry_delay"`
}

InspectedJob describes a job in a queue.

type InspectedJobs

type InspectedJobs struct {
	Jobs       []InspectedJob `json:"jobs"`
	NextCursor string         `json:"next_cursor"`
}

InspectedJobs describes a (page of) job list in a queue.

type Inspector

type Inspector interface {
	Delete(jobID uint64) error
	Find(jobID uint64) (*InspectedJob, error)
	FindAllGrabbed(limit uint, cursor string, order SortOrder) (*InspectedJobs, error)
	FindAllWaiting(limit uint, cursor string, order SortOrder) (*InspectedJobs, error)
	FindAllDeferred(limit uint, cursor string, order SortOrder) (*InspectedJobs, error)
}

Inspector is an interface to inspect jobs in a queue.

type Job

type Job interface {
	URL() string
	Payload() string
	Timeout() uint

	RetryCount() uint
	RetryDelay() uint
	FailCount() uint

	ToLoggable() logger.LoggableJob
}

Job is an interface of jobs.

type JobQueue

type JobQueue interface {
	Stop() <-chan struct{}
	Push(job IncomingJob) (uint64, error)
	Pop(limit uint) ([]Job, error)
	Complete(job Job, res *Result)

	Name() string

	IsActive() bool
	Node() (*Node, error)
	Stats() *Stats

	Inspector() (Inspector, bool)
	FailureLog() (FailureLog, bool)
}

JobQueue is an interface of a job queue.

func Start

func Start(definition *model.Queue, q Impl) JobQueue

Start returns a job queue.

type NextInfo

type NextInfo interface {
	NextDelay() uint64
	RetryCount() uint
	FailCount() uint
}

NextInfo describes information of a retry.

type Node

type Node struct {
	ID   string `json:"id"`
	Host string `json:"host"`
}

Node describes information of an active queue node.

type Result

type Result struct {
	Status  string `json:"status"`
	Code    int    `json:"code"`
	Message string `json:"message"`
}

Result describes the result of a processed job.

func (*Result) IsFailure

func (rslt *Result) IsFailure() bool

IsFailure returns if the job is successfully processed or not.

func (*Result) IsFinished

func (rslt *Result) IsFinished() bool

IsFinished returns if the job can be retried or not.

func (*Result) IsPermanentFailure added in v1.0.2

func (rslt *Result) IsPermanentFailure() bool

IsPermanentFailure returns if the job is permanently failed.

func (*Result) IsSuccess added in v1.1.0

func (rslt *Result) IsSuccess() bool

IsSuccess returns if the job succeeded

func (*Result) IsValid

func (rslt *Result) IsValid() bool

IsValid returns if the result status is valid or not.

type SortOrder added in v1.2.1

type SortOrder int

SortOrder describes sort order at inspecting jobs.

const (
	Asc SortOrder = iota
	Desc
)

Sort orders

type Stats

type Stats struct {
	TotalPushes            int64 `json:"total_pushes"`
	TotalPops              int64 `json:"total_pops"`
	TotalSuccesses         int64 `json:"total_successes"`
	TotalFailures          int64 `json:"total_failures"`
	TotalPermanentFailures int64 `json:"total_permanent_failures"`
	TotalCompletes         int64 `json:"total_completes"`
	TotalElapsed           int64 `json:"total_elapsed"`
	PushesPerSecond        int64 `json:"pushes_per_second"`
	PopsPerSecond          int64 `json:"pops_per_second"`
}

Stats describes queue statistics.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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