batchs

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: May 5, 2016 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrTask means a task had a non-zero exit code
	ErrTask = errors.New("error running a task")
)

Functions

This section is empty.

Types

type Context

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

Context tracks the path of where we store the queues. It is the only structure which knows about how the queues are persisted to disk. It should be promoted to an interface, probably.

func NewContext

func NewContext(q JobSource, taskpath, version string) *Context

NewContext creates a new context structure. taskpath is used to resolve task names into commands.

func (*Context) Run

func (ctx *Context) Run() error

Run the main event loop forever. Errors are logged. This function never returns.

type Job

type Job struct {
	Todo     []string // FIFO list of task names to execute
	Finished []Task   // list of finished tasks, from earliest to latest
	// contains filtered or unexported fields
}

Job collects all the logical consists of a single processing job. It is, essentially, a list of tasks.

type JobSource

type JobSource interface {
	// Perform any initializations
	Init() error
	// Return the next available job. Block until one is available.
	// May return a job AND an error, in which case the job should be finalized.
	NextJob() (*Job, error)
	// Save and finalize the given job
	FinishJob(job *Job) error
}

A JobSource abstracts the way the main processor gets jobs.

func NewFileQueue

func NewFileQueue(basepath string) JobSource

NewFileQueue creates a new FileQueue JobSource having its state directories at basepath.

type State

type State int

State encodes the processing status of a Job.

const (
	// StateUnknown is the "zero state"
	StateUnknown State = iota
	// StateQueue means job is awaiting processing
	StateQueue
	// StateProcessing means job is being processed
	StateProcessing
	// StateSuccess means job is finished and was successful
	StateSuccess
	// StateError means job is done being processed and there was an error
	StateError
)

func (State) String

func (s State) String() string

type Task

type Task struct {
	Name   string
	Start  time.Time
	Finish time.Time
	Status string
}

Task is a singular work item inside a Job.

Jump to

Keyboard shortcuts

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