job

package
v0.0.0-...-1045ef1 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetJobsCollectionName

func GetJobsCollectionName(deployment string) string

func NewBufferedQueue

func NewBufferedQueue(queueSize uint) chan Job

NewBufferedQueue : create a buffered channel for queuing jobs

func Queue

func Queue() chan Job

Queue : get the job queue

func SortASC

func SortASC(a, b Job) bool

func SortDESC

func SortDESC(a, b Job) bool

Types

type Enqueuer

type Enqueuer struct {
	Handler GenericHandler
	// contains filtered or unexported fields
}

func NewEnqueuer

func NewEnqueuer(jobQueue chan Job) Enqueuer

func (*Enqueuer) Enqueue

func (e *Enqueuer) Enqueue(job Job) (Job, error)

type Error

type Error struct {
	Execution uint   `json:"execution"`
	Message   string `json:"message"`
}

type GenericHandler

type GenericHandler func(args interface{}) error

GenericHandler is a generic job handler that takes in job arguments

type Job

type Job struct {
	ID          string         `json:"id"`               // Unique job ID
	Deployment  string         `json:"deployment"`       // Deployment used for scoping jobs.
	Type        string         `json:"type"`             // The type of job
	Status      Status         `json:"status"`           // The response of the current job with details for execution counts etc..
	State       State          `json:"state"`            // Current state of a job (running | complete)
	StartTime   int64          `json:"start_time_epoch"` // Job Start time - epoch in seconds since 1970
	EndTime     int64          `json:"end_time_epoch"`   // Job end time - epoch in seconds since 1970
	RetryPolicy uint           `json:"retry_policy"`     // Job retry policy
	Args        interface{}    `json:"-"`                // Arguments passed down to job handlers
	Setup       GenericHandler `json:"-"`                // Setup is the initial execution fn for a job typically to setup arguments
	Run         GenericHandler `json:"-"`                // Run is the main executor fn for a job
	Finally     GenericHandler `json:"-"`                // Final fn is the final execution fn for a job
}

func (*Job) Serialize

func (j *Job) Serialize() ([]byte, error)

Serialize a job into bytes

func (*Job) WithError

func (j *Job) WithError(err error)

WithError adds an error to a job

type NJobs

type NJobs [][]Job

N dimensional Job array

func (NJobs) MergeAndSort

func (njobs NJobs) MergeAndSort(overlap SortOrder) []Job

merge : combines njobs into a single job array sorted in DESCENDING order based on timestamp.

type SortOrder

type SortOrder func(Job, Job) bool

type State

type State string
const (
	Started   State = "STARTED"
	Completed State = "COMPLETED"
)

type Status

type Status struct {
	ExecutionCount uint    `json:"execution_count"`
	FailureCount   uint    `json:"failure_count"`
	Failures       []Error `json:"failures"`
}

type Step

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

type WorkerPool

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

func NewWorkerPool

func NewWorkerPool(concurrency uint, jobChannel chan Job, store store.Store) WorkerPool

NewWorkerPool : create a concurrent pool of workers to process Jobs from the queue

func (*WorkerPool) Start

func (wp *WorkerPool) Start()

Start : all the workers part of the worker pool

func (*WorkerPool) Stop

func (wp *WorkerPool) Stop()

type Workflow

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

func NewWorkflow

func NewWorkflow(name string, args interface{}) Workflow

NewWorkflow : creates a new workflow

func (*Workflow) Start

func (wf *Workflow) Start() error

Start : executes every Step in a Workflow returns an error if any Step in the Workflow errors out.

func (*Workflow) With

func (wf *Workflow) With(name string, handler GenericHandler)

With : add new step to a workflow

Jump to

Keyboard shortcuts

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