Documentation ¶
Overview ¶
Package worker provides worker processes
Copyright (C) 2019-2021 vdaas.org vald team <vald@vdaas.org>
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Package worker provides worker processes ¶
Package worker provides worker processes ¶
Package worker provides worker processes
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( DefaultStartFunc = func(context.Context) (<-chan error, error) { return nil, nil } DefaultPushFunc = func(context.Context, JobFunc) error { return nil } DefaultPopFunc = func(context.Context) (JobFunc, error) { return nil, nil } DefaultLenFunc = func() uint64 { return uint64(0) } )
Functions ¶
This section is empty.
Types ¶
type Queue ¶
type Queue interface { Start(ctx context.Context) (<-chan error, error) Push(ctx context.Context, job JobFunc) error Pop(ctx context.Context) (JobFunc, error) Len() uint64 }
Queue represents the interface of queue.
func NewQueue ¶
func NewQueue(opts ...QueueOption) (Queue, error)
NewQueue returns Queue if no error is occurred.
func NewQueueMock ¶ added in v1.0.5
func NewQueueMock() Queue
type QueueMock ¶ added in v1.0.5
type QueueMock struct { StartFunc func(context.Context) (<-chan error, error) PushFunc func(context.Context, JobFunc) error PopFunc func(context.Context) (JobFunc, error) LenFunc func() uint64 }
type QueueOption ¶
type QueueOption func(q *queue) error
QueueOption represents the functional option for queue.
func WithQueueBuffer ¶
func WithQueueBuffer(buffer int) QueueOption
WithQueueBuffer returns the option to set the buffer for queue.
func WithQueueCheckDuration ¶ added in v0.0.30
func WithQueueCheckDuration(dur string) QueueOption
WithQueueCheckDuration returns the option to set the qcdur for queue. If dur is invalid string, it returns errror.
func WithQueueErrGroup ¶
func WithQueueErrGroup(eg errgroup.Group) QueueOption
WithQueueErrGroup returns the options to set the eg for queue.
type Worker ¶
type Worker interface { Start(ctx context.Context) (<-chan error, error) Pause() Resume() IsRunning() bool Name() string Len() uint64 TotalRequested() uint64 TotalCompleted() uint64 Dispatch(ctx context.Context, f JobFunc) error }
Worker represents the worker interface to execute jobs.
func New ¶
func New(opts ...WorkerOption) (Worker, error)
New initializes and return the worker, or return initialization error if occurred.
type WorkerOption ¶
type WorkerOption func(w *worker) error
func WithErrGroup ¶
func WithErrGroup(eg errgroup.Group) WorkerOption
func WithLimitation ¶
func WithLimitation(limit int) WorkerOption
func WithName ¶
func WithName(name string) WorkerOption
func WithQueueOption ¶ added in v0.0.30
func WithQueueOption(opts ...QueueOption) WorkerOption