worker

package
v1.5.3 Latest Latest
Warning

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

Go to latest
Published: May 25, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package worker provides worker processes

Copyright (C) 2019-2022 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

View Source
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 JobFunc

type JobFunc func(context.Context) error

JobFunc represents the function of a job that works in the worker.

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
}

func (*QueueMock) Len added in v1.0.5

func (q *QueueMock) Len() uint64

func (*QueueMock) Pop added in v1.0.5

func (q *QueueMock) Pop(ctx context.Context) (JobFunc, error)

func (*QueueMock) Push added in v1.0.5

func (q *QueueMock) Push(ctx context.Context, job JobFunc) error

func (*QueueMock) Start added in v1.0.5

func (q *QueueMock) Start(ctx context.Context) (<-chan error, error)

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

Jump to

Keyboard shortcuts

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