worm

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2017 License: MIT Imports: 12 Imported by: 0

README

worm.io

Batch and scheduler written in Go.

Documentation

Overview

Package worm contains worm.io Queue.

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Index

Constants

View Source
const (
	// StatusStart default job status.
	StatusStart = 1
	// StatusOK success status code.
	StatusOK = 0
)

Variables

This section is empty.

Functions

func Close

func Close() error

Close close database connections.

func Connect

func Connect(connectURL, logDir string) error

Connect starts a default worm hub.

func CopyLog

func CopyLog(w io.Writer, jobID string) error

CopyLog write the content of log file to w.

func DB

func DB() *sqlx.DB

DB returns the default worm Db. Use it only for queries more complicated than Query method.

func MustRegister

func MustRegister(workerName string, doer Doer)

MustRegister _

func Printf

func Printf(w io.Writer, format string, args ...interface{})

Printf convenience.

func Println

func Println(w io.Writer, args ...interface{})

Println convenience.

func Queue

func Queue(workerName string, data []byte) (string, error)

Queue _

func Register

func Register(workerName string, doer Doer) error

Register _

func Sched

func Sched(workerName string, data []byte, cronformat string) (string, error)

Sched _

Types

type Doer

type Doer interface {
	// Name returns worker name.
	Name() string

	// Run executes the job and Worm writes the logOut to a file and state to
	// database.
	// If success state returned must be zero.
	Run(data []byte, logOutput io.Writer) (state int, err error)
}

Doer interface. Your implementation must make sure that resources are only available there and reusable. For example you 'almost' everytime will need only one database connection for resources economy.

type Job

type Job struct {
	ID        string    `db:"id" json:"id"`
	Worker    string    `db:"worker_name" json:"worker_name"`
	Status    int       `db:"status" json:"status"`
	Error     string    `db:"error" json:"error"`
	LogFile   string    `db:"log_file" json:"log_file"`
	Data      string    `db:"data" json:"data"`
	CreatedAt time.Time `db:"created_at" json:"created_at"`
}

Job struct for database query.

func Detail

func Detail(ID string) (*Job, error)

Detail _

func Query

func Query(before, after time.Time, limit int) ([]*Job, error)

Query _

type Worm

type Worm struct {
	Db *sqlx.DB

	sync.RWMutex
	// contains filtered or unexported fields
}

Worm struct.

func New

func New(connectURL, logDir string) (*Worm, error)

New connects to sqlite database and returns a new Worm hub.

func (*Worm) Close

func (h *Worm) Close() error

Close close database connections.

func (*Worm) CopyLog

func (h *Worm) CopyLog(w io.Writer, jobID string) error

CopyLog return the job detail by id.

func (*Worm) Detail

func (h *Worm) Detail(ID string) (*Job, error)

Detail return the job detail by id.

func (*Worm) MustRegister

func (h *Worm) MustRegister(workerName string, doer Doer)

MustRegister register the worker interface for this worm.

func (*Worm) Queue

func (h *Worm) Queue(workerName string, data []byte) (string, error)

Queue will cron the job for execution on cronformat.

func (*Worm) Register

func (h *Worm) Register(workerName string, doer Doer) error

Register register the worker for this worm. Must be called at init time.

func (*Worm) Sched

func (h *Worm) Sched(workerName string, data []byte, cronformat string) (string, error)

Sched will cron the job for execution on cronformat.

Directories

Path Synopsis
examples
basic
Package main contains example for worm server and queue.
Package main contains example for worm server and queue.

Jump to

Keyboard shortcuts

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