taskq

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2021 License: MIT Imports: 7 Imported by: 1

README

TaskQ

Go Report GoDoc Build Status Codecov

Goroutine manager.


Installing

go get github.com/antonmashko/taskq

TaskQ

Initializing

Use TaskQ for managing you goroutines.

taskq := New(<size>)

size - parameter will control goroutines count. In case if all goroutines are busy, task will be added to queue and will wait for a free worker (goroutine) from pool.

Add task to TaskQ
taskID := taskq.Enqueue(<task>)
Start TaskQ
err := taskq.Start()

run all added and future tasks in taskq.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrRetryTask = errors.New("error occurred during task execution. retry task")

Functions

This section is empty.

Types

type ConcurrentQueue added in v0.4.0

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

func (*ConcurrentQueue) Dequeue added in v0.4.0

func (q *ConcurrentQueue) Dequeue() Task

func (*ConcurrentQueue) Enqueue added in v0.4.0

func (q *ConcurrentQueue) Enqueue(t Task)

type LimitedConcurrentQueue added in v0.4.0

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

func (*LimitedConcurrentQueue) Dequeue added in v0.4.0

func (q *LimitedConcurrentQueue) Dequeue() Task

func (*LimitedConcurrentQueue) Enqueue added in v0.4.0

func (q *LimitedConcurrentQueue) Enqueue(t Task)

type Queue added in v0.4.0

type Queue interface {
	Enqueue(Task)
	Dequeue() Task
}

func NewConcurrentQueue added in v0.4.0

func NewConcurrentQueue() Queue

func NewLimitedConcurrentQueue added in v0.4.0

func NewLimitedConcurrentQueue(size int) Queue

type RetryableTask

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

func (*RetryableTask) Do

func (t *RetryableTask) Do(ctx context.Context) error

type Status

type Status byte
const (
	None Status = iota
	Pending
	InProgress
	Done
	Failed
)

func TaskStatus

func TaskStatus(task Task) Status

type Task

type Task interface {
	Do(ctx context.Context) error
}

Task for TaskQ

func NewRetryableTask

func NewRetryableTask(task Task, maxRetries int) Task

type TaskFunc

type TaskFunc func(ctx context.Context) error

func (TaskFunc) Do

func (t TaskFunc) Do(ctx context.Context) error

type TaskManager

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

func NewTaskManger

func NewTaskManger(taskQ *TaskQ) *TaskManager

func (*TaskManager) Close

func (m *TaskManager) Close() error

func (*TaskManager) Enqueue

func (m *TaskManager) Enqueue(task Task) int64

func (*TaskManager) Shutdown added in v0.3.0

func (m *TaskManager) Shutdown(ctx context.Context) error

func (*TaskManager) Start

func (m *TaskManager) Start() error

func (*TaskManager) Task

func (m *TaskManager) Task(id int64) Task

type TaskQ

type TaskQ struct {
	TaskDone   func(int64, Task)
	TaskFailed func(int64, Task, error)
	// contains filtered or unexported fields
}

func New

func New(size int) *TaskQ

func NewWithQueue added in v0.4.0

func NewWithQueue(size int, q Queue) *TaskQ

func (*TaskQ) Close

func (t *TaskQ) Close() error

func (*TaskQ) Enqueue

func (t *TaskQ) Enqueue(task Task) int64

func (*TaskQ) Shutdown added in v0.3.0

func (t *TaskQ) Shutdown(ctx context.Context) error

func (*TaskQ) Start

func (t *TaskQ) Start() error

type TaskQInterface added in v0.2.1

type TaskQInterface interface {
	Enqueue(Task) int64
	Start() error
	Shutdown(ctx context.Context) error
	Close() error
}

type WaitGroup added in v0.2.1

type WaitGroup struct {
	TaskQInterface
	// contains filtered or unexported fields
}

func ConvertToWaitGroup added in v0.2.1

func ConvertToWaitGroup(taskq TaskQInterface) *WaitGroup

func NewWaitGroup added in v0.2.1

func NewWaitGroup(size int) *WaitGroup

func (*WaitGroup) Enqueue added in v0.2.1

func (wg *WaitGroup) Enqueue(task Task) int64

func (*WaitGroup) Wait added in v0.2.1

func (wg *WaitGroup) Wait()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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