jobs

package module
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2019 License: MIT Imports: 9 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Close

func Close() error

Close closes the jobs queue. It is save to call it multiple times.

func Init

func Init(dtb db.DB) error

Init initializes the jobs queue and the jobs database tables (if they do not yet exist). It must be called before any other functions in this package and must not called concurrently with any other functions in this package.

func Job

func Job(id int) *api.JobStatus

Job returns information about the job with the given id. If the job cannot be found or if any other error occurs, a job with db.StatusFailed is returned.

func Run added in v0.5.2

func Run(ctx context.Context, cmd string, args ...string) error

Run executes a command with the given context and arguments. The command's stderr is logged using log.Debug. Run waits for the command to finish and returns its result.

func Start

func Start(ctx context.Context, r Runner) (int, error)

Start runs the given callback function as a background job. It starts the job in the background and immediately returns the job id without blocking. If a job for the given book is already running, this job's id information is returned. You can check the status of the job with the Job function at any given time.

Types

type Runner added in v0.5.0

type Runner interface {
	BookID() int               // returns the book id of the job
	Name() string              // returns the name of the job
	Run(context.Context) error // runs the job
}

Runner defines the interface for any running job

Jump to

Keyboard shortcuts

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