queue

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2023 License: MIT Imports: 8 Imported by: 1

Documentation

Index

Constants

View Source
const (
	DefaultRetryLimit = 5
)
View Source
const (
	DefaultSqSize = 1024
)

Variables

View Source
var (
	ErrTaskStopped      = fmt.Errorf("task is stopped")
	ErrRetryReachLimits = fmt.Errorf("retry reaches limits")
	ErrFailReachLimits  = fmt.Errorf("fails reaches limits")
)
View Source
var (
	ErrPollableEventsNotExists = fmt.Errorf("the pollable event doesn't exist")
)
View Source
var (
	ErrQueueClosed = fmt.Errorf("queue is closed")
)

Functions

This section is empty.

Types

type Failure added in v1.0.1

type Failure func(fail int, task Task)

type FairQueue

type FairQueue struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*FairQueue) Cap

func (f *FairQueue) Cap() int

func (*FairQueue) Close

func (f *FairQueue) Close()

close wait until all tasks are executed.

func (*FairQueue) Copy

func (f *FairQueue) Copy() []Task

func (*FairQueue) ForcePublish

func (f *FairQueue) ForcePublish(t Task) error

func (*FairQueue) Free

func (f *FairQueue) Free() int

func (*FairQueue) IsClosed

func (f *FairQueue) IsClosed() bool

func (*FairQueue) Len

func (f *FairQueue) Len() int

func (*FairQueue) Pop

func (f *FairQueue) Pop() (Task, error)

func (*FairQueue) Publish

func (f *FairQueue) Publish(t Task) bool

func (*FairQueue) Resize

func (f *FairQueue) Resize(cap int) bool

func (*FairQueue) Save

func (f *FairQueue) Save(_ func(Task))

func (*FairQueue) Subscribe

func (f *FairQueue) Subscribe() (chan Task, error)

func (*FairQueue) TryPop

func (f *FairQueue) TryPop() (Task, bool)

type Finalizer

type Finalizer func(ok bool, task Task)

type NewQueue

type NewQueue func(...Options) Queue

type Options

type Options func(queue Queue)

func WithFairQueueCap

func WithFairQueueCap(cap int) Options

func WithSimpleQueueCap

func WithSimpleQueueCap(cap int) Options

type PollTask

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

func NewPoll

func NewPoll() *PollTask

func (*PollTask) Callback

func (p *PollTask) Callback(id string, f Finalizer) error

func (*PollTask) ForEach

func (p *PollTask) ForEach(f func(string, Pollable) bool)

func (*PollTask) Get

func (p *PollTask) Get(id string) (Pollable, bool)

func (*PollTask) Kill

func (p *PollTask) Kill(id string) error

func (*PollTask) Poll

func (p *PollTask) Poll(f func(string, Pollable))

func (*PollTask) PollOne

func (p *PollTask) PollOne(id string) (bool, error)

func (*PollTask) Register

func (p *PollTask) Register(pb Pollable)

func (*PollTask) Remove

func (p *PollTask) Remove(pb Pollable)

type Pollable

type Pollable interface {
	Task
}

type Queue

type Queue interface {
	IsClosed() bool
	Publish(Task) bool
	ForcePublish(Task) error
	Subscribe() (chan Task, error)
	Close()
	TryPop() (Task, bool)
	Pop() (Task, error)
	Resize(int) bool
	Cap() int
	Len() int
	Free() int
	Copy() []Task
	// Save() acts like Copy()
	// but it only allows to call once.
	Save(func(Task))
}

func NewFairQueue

func NewFairQueue(opts ...Options) Queue

func NewSimpleQueue

func NewSimpleQueue(opts ...Options) Queue

type RetryFunc

type RetryFunc func(*TaskEntry) error

func DefaultRetry

func DefaultRetry() RetryFunc

type SimpleQueue

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

func (*SimpleQueue) Cap

func (s *SimpleQueue) Cap() int

func (*SimpleQueue) Close

func (s *SimpleQueue) Close()

close wait until all tasks are executed.

func (*SimpleQueue) Copy

func (s *SimpleQueue) Copy() []Task

func (*SimpleQueue) ForcePublish

func (s *SimpleQueue) ForcePublish(t Task) error

func (*SimpleQueue) Free

func (s *SimpleQueue) Free() int

func (*SimpleQueue) IsClosed

func (s *SimpleQueue) IsClosed() bool

func (*SimpleQueue) Len

func (s *SimpleQueue) Len() int

func (*SimpleQueue) Pop

func (s *SimpleQueue) Pop() (Task, error)

func (*SimpleQueue) Publish

func (s *SimpleQueue) Publish(t Task) bool

func (*SimpleQueue) Resize

func (s *SimpleQueue) Resize(capSize int) bool

func (*SimpleQueue) Save

func (s *SimpleQueue) Save(f func(Task))

func (*SimpleQueue) Subscribe

func (s *SimpleQueue) Subscribe() (chan Task, error)

func (*SimpleQueue) TryPop

func (s *SimpleQueue) TryPop() (Task, bool)

type Task

type Task interface {
	Do() error
	Error() error
	TaskError() error
	ID() string
	Stop()
	Interrupt()
	IsDone() bool
	// The action function when tasks is stop or interrputed.
	OnDone(...Finalizer)
	// The action function when tasks run fail.
	OnFail(...Failure)
	Wait()
	String() string
	IsRunUntilSuccess() bool
	IsReachLimits() bool
	SetTaskError(error)
	TaskContext() *sync.Map
}

func NewTask

func NewTask(task TaskFunc, opts ...TaskOptions) Task

type TaskEntry

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

func (*TaskEntry) Do

func (t *TaskEntry) Do() error

func (*TaskEntry) Error

func (t *TaskEntry) Error() error

func (*TaskEntry) ID

func (t *TaskEntry) ID() string

func (*TaskEntry) Interrupt

func (t *TaskEntry) Interrupt()

func (*TaskEntry) IsDone

func (t *TaskEntry) IsDone() bool

func (*TaskEntry) IsReachLimits

func (t *TaskEntry) IsReachLimits() bool

func (*TaskEntry) IsRunUntilSuccess

func (t *TaskEntry) IsRunUntilSuccess() bool

func (*TaskEntry) OnDone

func (t *TaskEntry) OnDone(f ...Finalizer)

func (*TaskEntry) OnFail added in v1.0.1

func (t *TaskEntry) OnFail(f ...Failure)

func (*TaskEntry) SetTaskError

func (t *TaskEntry) SetTaskError(err error)

func (*TaskEntry) Stop

func (t *TaskEntry) Stop()

func (*TaskEntry) String

func (t *TaskEntry) String() string

func (*TaskEntry) TaskContext

func (t *TaskEntry) TaskContext() *sync.Map

func (*TaskEntry) TaskError

func (t *TaskEntry) TaskError() error

func (*TaskEntry) Wait

func (t *TaskEntry) Wait()

type TaskFunc

type TaskFunc func() error

type TaskOptions

type TaskOptions func(*TaskEntry)

func LockRequired

func LockRequired() TaskOptions

func WithContext

func WithContext(ctx context.Context) TaskOptions

func WithFailLimits

func WithFailLimits(limits int) TaskOptions

func WithNoRetryFunc

func WithNoRetryFunc() TaskOptions

fail fast. which promises the task will run once.

func WithOnTaskDone

func WithOnTaskDone(f Finalizer) TaskOptions

func WithOnTaskFail added in v1.0.1

func WithOnTaskFail(f Failure) TaskOptions

func WithRetryFunc

func WithRetryFunc(retry RetryFunc) TaskOptions

func WithRetryLimit

func WithRetryLimit(retry int) TaskOptions

when the custom RetryFunc is set, the retry limit will be ignored.

func WithRunUntilSuccess

func WithRunUntilSuccess(RunUntilSuccess bool) TaskOptions

func WithTaskID

func WithTaskID(id string) TaskOptions

Jump to

Keyboard shortcuts

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