tsq

package module
v0.0.0-...-4e2ccdb Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2019 License: BSD-2-Clause Imports: 16 Imported by: 0

README

Single task queue

Getting Started

[jeroen@jhoekx-laptop tsq]$ pwd
/home/jeroen/dev/go/src/github.com/jhoekx/tsq
[jeroen@jhoekx-laptop tsq]$ go get github.com/mattn/go-sqlite3
[jeroen@jhoekx-laptop tsq]$ go install github.com/mattn/go-sqlite3
[jeroen@jhoekx-laptop tsq]$ go test
PASS
ok      github.com/jhoekx/tsq   0.003s
[jeroen@jhoekx-laptop tsq]$ cd examples/sqlite/
[jeroen@jhoekx-laptop sqlite]$ go run sqlite.go
2017/01/13 11:10:02 Running migration: V1__001_CreateJobDB
[jeroen@jhoekx-laptop sqlite]$ curl -X GET http://localhost:8000/tsq/
[{"name":"tasks","href":"/tsq/tasks/"},{"name":"jobs","href":"/tsq/jobs/"}]
[jeroen@jhoekx-laptop sqlite]$ curl -X POST http://localhost:8000/tsq/tasks/sleep-5/
{"uuid":"85724738-97aa-404d-8007-add0c6bec1cf","name":"sleep-5","status":"PENDING","arguments":null,"result":null,"created":"2017-11-17T21:26:22.723086282+01:00","updated":"2017-11-17T21:26:22.723086282+01:00","href":"/tsq/jobs/85724738-97aa-404d-8007-add0c6bec1cf/"}
[jeroen@jhoekx-laptop sqlite]$ curl -X POST http://localhost:8000/tsq/tasks/sleep-5/?jobTimeoutSeconds=10
{"uuid":"6cb844cb-261c-454d-a52f-1c53f3394175","name":"sleep-5","status":"SUCCESS","arguments":"","result":{"stderr":"","stdout":""},"created":"2017-11-17T21:26:05.283245685+01:00","updated":"2017-11-17T21:26:10.306581887+01:00","href":"/tsq/jobs/6cb844cb-261c-454d-a52f-1c53f3394175/"}
[jeroen@jhoekx-laptop examples]$ curl -X POST http://localhost:8000/tsq/tasks/sleep-5/?jobTimeoutSeconds=1
HTTP 504 Timed out waiting for job f76344fd-ce62-49f5-b628-515d759321bc

Documentation

Index

Constants

View Source
const (
	JOB_PENDING = "PENDING"
	JOB_RUNNING = "RUNNING"
	JOB_SUCCESS = "SUCCESS"
	JOB_FAILURE = "FAILURE"
)

Variables

This section is empty.

Functions

func CreateJobDB

func CreateJobDB(db *sql.DB) (err error)

func ServeQueue

func ServeQueue(baseURL string, q *TaskQueue) http.Handler

Types

type CommandTask

type CommandTask struct {
	Cmd  string
	Args []string
}

func NewCommandTask

func NewCommandTask(Cmd string, Args ...string) CommandTask

func (*CommandTask) Run

func (t *CommandTask) Run(arguments interface{}) (data interface{}, err error)

type Config

type Config struct {
	QueueLength int
	JobStore    JobStore
}
var DefaultConfig Config = Config{
	QueueLength: 10,
	JobStore:    NewMemoryStore(),
}

func (*Config) NewQueue

func (config *Config) NewQueue() (q *TaskQueue)

type Job

type Job struct {
	UUID      string      `json:"uuid"`
	Name      string      `json:"name"`
	Status    string      `json:"status"`
	Arguments interface{} `json:"arguments"`
	Result    interface{} `json:"result"`
	Created   time.Time   `json:"created"`
	Updated   time.Time   `json:"updated"`
}

func (*Job) HasFinished

func (job *Job) HasFinished() bool

type JobStore

type JobStore interface {
	LifeCycle
	Store(job *Job) error
	GetJob(uuid string) (*Job, error)
	SetStatus(uuid string, status string, updated time.Time) error
	SetResult(uuid string, result interface{}) error
	GetJobs() ([]*Job, error)
}

func NewMemoryStore

func NewMemoryStore() JobStore

func NewSQLiteStore

func NewSQLiteStore() JobStore

type LifeCycle

type LifeCycle interface {
	Start() error
	Stop()
}

type MemoryStore

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

func (*MemoryStore) GetJob

func (s *MemoryStore) GetJob(uuid string) (job *Job, err error)

func (*MemoryStore) GetJobs

func (s *MemoryStore) GetJobs() ([]*Job, error)

func (*MemoryStore) SetResult

func (s *MemoryStore) SetResult(uuid string, result interface{}) (err error)

func (*MemoryStore) SetStatus

func (s *MemoryStore) SetStatus(uuid string, status string, updated time.Time) (err error)

func (*MemoryStore) Start

func (s *MemoryStore) Start() (err error)

func (*MemoryStore) Stop

func (s *MemoryStore) Stop()

func (*MemoryStore) Store

func (s *MemoryStore) Store(job *Job) error

type Migration

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

type MigrationFn

type MigrationFn func(*sql.DB) error

type Migrations

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

func NewMigrations

func NewMigrations(db *sql.DB) *Migrations

func (*Migrations) Register

func (ms *Migrations) Register(version string, migration MigrationFn)

func (*Migrations) Run

func (ms *Migrations) Run() (err error)

type NameRef

type NameRef struct {
	Name string `json:"name"`
	Href string `json:"href"`
}

type Runner

type Runner interface {
	Run(args interface{}) (interface{}, error)
}

type SQLRow

type SQLRow interface {
	Scan(...interface{}) error
}

type SQLiteStore

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

func (*SQLiteStore) GetJob

func (s *SQLiteStore) GetJob(uuid string) (*Job, error)

func (*SQLiteStore) GetJobs

func (s *SQLiteStore) GetJobs() (jobs []*Job, err error)

func (*SQLiteStore) SetResult

func (s *SQLiteStore) SetResult(uuid string, result interface{}) (err error)

func (*SQLiteStore) SetStatus

func (s *SQLiteStore) SetStatus(uuid string, status string, updated time.Time) (err error)

func (*SQLiteStore) Start

func (s *SQLiteStore) Start() (err error)

func (*SQLiteStore) Stop

func (s *SQLiteStore) Stop()

func (*SQLiteStore) Store

func (s *SQLiteStore) Store(job *Job) (err error)

type TaskQueue

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

func New

func New() *TaskQueue

func (*TaskQueue) Define

func (q *TaskQueue) Define(name string, r Runner)

func (*TaskQueue) GetJob

func (q *TaskQueue) GetJob(uuid string) (*Job, error)

func (*TaskQueue) GetJobs

func (q *TaskQueue) GetJobs() (jobs []*Job, err error)

func (*TaskQueue) Start

func (q *TaskQueue) Start() (err error)

func (*TaskQueue) Stop

func (q *TaskQueue) Stop()

func (*TaskQueue) Submit

func (q *TaskQueue) Submit(name string, arguments interface{}) (job *Job, err error)

type WebJob

type WebJob struct {
	*Job
	Href string `json:"href"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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