package module
Version: v0.0.3 Latest Latest

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

Go to latest
Published: Sep 2, 2020 License: MIT Imports: 11 Imported by: 0



Wrapper around the awesome machinery go library for background task execution

Status: Work In progress


  • Limited and simplified wrapper.
  • Pass around struct as task parameter (gets converted to gob)

Create the JobQueue. Pass the redis URL as parameter to New()

jq, err := machine.New("redis://")


Implement a "TaskExecuter" that can execute a "task" TaskExecuter interface

type TaskExecutor interface {
	Execute(interface{}) error


type RunnableTask interface {
	GetTaskID() string

Register the task executer with JobQueue

jq.Register(&OrderEmail{}, orderSvc)

Now push tasks to the queue

task := &OrderEmail{email, orderID}
job := machine.NewJob(&task)

Your TaskExecutor gets called when the task is due

func (*OrderService) Execute(t interface{})error{
    switch t.(type){
        case OrderEmail:
            return sendEmail(t)
        case PaymentUpdate:
            return updatePayment(t)
    return nil

Delayed jobs

task := &ConfirmationEmail{email}

job := machine.NewJob(task).After(5*time.Minutes)

Stop the queue (and the workers)





This section is empty.


This section is empty.


This section is empty.


type EmptyLog added in v0.0.3

type EmptyLog struct {

func NewEmptyLog added in v0.0.3

func NewEmptyLog() *EmptyLog

func (*EmptyLog) Fatal added in v0.0.3

func (*EmptyLog) Fatal(...interface{})

func (*EmptyLog) Fatalf added in v0.0.3

func (*EmptyLog) Fatalf(string, ...interface{})

func (*EmptyLog) Fatalln added in v0.0.3

func (*EmptyLog) Fatalln(...interface{})

func (*EmptyLog) Panic added in v0.0.3

func (*EmptyLog) Panic(...interface{})

func (*EmptyLog) Panicf added in v0.0.3

func (*EmptyLog) Panicf(string, ...interface{})

func (*EmptyLog) Panicln added in v0.0.3

func (*EmptyLog) Panicln(...interface{})

func (*EmptyLog) Print added in v0.0.3

func (*EmptyLog) Print(...interface{})

func (*EmptyLog) Printf added in v0.0.3

func (*EmptyLog) Printf(string, ...interface{})

func (*EmptyLog) Println added in v0.0.3

func (*EmptyLog) Println(...interface{})

type InternalTaskExecutor

type InternalTaskExecutor struct {
	// contains filtered or unexported fields

func (*InternalTaskExecutor) DoTask

func (te *InternalTaskExecutor) DoTask(jb []uint8) error

func (*InternalTaskExecutor) MakeTask

func (te *InternalTaskExecutor) MakeTask(job *Job) (*tasks.Signature, error)

func (*InternalTaskExecutor) Register

func (te *InternalTaskExecutor) Register(task interface{}, tex TaskExecutor)

type Job

type Job struct {
	Task RunnableTask
	Due  time.Time

func NewJob

func NewJob(t RunnableTask) *Job

func (*Job) After

func (j *Job) After(d time.Duration) *Job

func (*Job) IsScheduled

func (j *Job) IsScheduled() bool

type JobQueue

type JobQueue struct {
	NumWorkers int
	// contains filtered or unexported fields

func New

func New(redisURL string) (*JobQueue, error)

func (*JobQueue) QueueUp

func (jq *JobQueue) QueueUp(job *Job) error

func (*JobQueue) Register

func (jq *JobQueue) Register(task interface{}, tex TaskExecutor)

func (*JobQueue) ScheduleRecurringJob added in v0.0.2

func (jq *JobQueue) ScheduleRecurringJob(job *Job, repeat time.Duration)

func (*JobQueue) Start

func (jq *JobQueue) Start()

func (*JobQueue) Stop

func (jq *JobQueue) Stop()

func (*JobQueue) Workers

func (d *JobQueue) Workers(n int) *JobQueue

type RunnableTask

type RunnableTask interface {
	GetTaskID() string

type TaskExecutor

type TaskExecutor interface {
	Execute(interface{}) error


Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL