taskq

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: May 26, 2021 License: MIT Imports: 5 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 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()

func (*TaskManager) Enqueue

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

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 (*TaskQ) Close

func (t *TaskQ) Close()

func (*TaskQ) Enqueue

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

func (*TaskQ) Start

func (t *TaskQ) Start() error

type TaskQInterface added in v0.2.1

type TaskQInterface interface {
	Enqueue(Task) int64
	Start() error
	Close()
}

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