task

package
v0.10.3 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2023 License: Apache-2.0 Imports: 12 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// WAITING the job is waiting
	WAITING = iota + 1

	// RUNNING the job is running
	RUNNING

	// SUCCESS the job is success
	SUCCESS

	// FAILURE the job is failure
	FAILURE
)

Variables

View Source
var TaskHandlers = map[string]process.Handler{
	"add":      processTaskAdd,
	"progress": processTaskProgress,
	"get":      processTaskGet,
}

TaskHandlers task process handlers

View Source
var Tasks = map[string]*Task{}

Tasks the registered tasks

Functions

func Progress

func Progress(name string, id, curr, total int, message string) error

Progress set the progress of the job

Types

type Handlers

type Handlers struct {
	Exec     func(int, ...interface{}) (interface{}, error)
	Progress func(int, int, int, string)
	NextID   func() (int, error)
	Add      func(int)
	Success  func(int, interface{})
	Error    func(int, error)
}

Handlers the event handlers

type Job

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

Job the job

type Option

type Option struct {
	Name           string
	JobQueueLength int
	WorkerNums     int
	AttemptAfter   int
	Attempts       int
	Timeout        int
}

Option the task option

type Pool

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

Pool the worker pool

type ProcessOption added in v0.10.3

type ProcessOption struct {
	Name         string      `json:"name"`
	Process      string      `json:"process"`
	Size         interface{} `json:"size,omitempty"`
	WorkerNums   interface{} `json:"worker_nums,omitempty"`
	AttemptAfter interface{} `json:"attempt_after,omitempty"`
	Attempts     interface{} `json:"attempts,omitempty"`
	Timeout      interface{} `json:"timeout,omitempty"`
	Event        struct {
		Next     string `json:"next,omitempty"`
		Add      string `json:"add,omitempty"`
		Success  string `json:"success,omitempty"`
		Error    string `json:"error,omitempty"`
		Progress string `json:"progress,omitempty"`
	} `json:"event"`
}

ProcessOption the task process option

type Task

type Task struct {
	Option Option
	// contains filtered or unexported fields
}

Task the task struct

func Load added in v0.10.3

func Load(file string, name string) (*Task, error)

Load load task

func New

func New(handlers *Handlers, option Option) *Task

New create new task

func Select added in v0.10.3

func Select(name string) *Task

Select select task by name

func (*Task) Add

func (t *Task) Add(args ...interface{}) (int, error)

Add a job to the job queue

func (*Task) Get

func (t *Task) Get(id int) (map[string]interface{}, error)

Get get job by job id

func (*Task) Start

func (t *Task) Start()

Start start the worker pool

func (*Task) Stop

func (t *Task) Stop()

Stop the task

type Worker

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

Worker the work struct

Jump to

Keyboard shortcuts

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