redisw

package module
v0.0.0-...-f5c3624 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2022 License: MIT Imports: 7 Imported by: 0

README

Redis adapter for Go Worker

This package implements the github.com/purposeinplay/go-worker/ Worker interface using the github.com/gocraft/work package.

Setup

import "github.com/purposeinplay/go-worker/redisw"
import "github.com/gomodule/redigo/redis"

// Make a redis pool
redisPool := &redis.Pool{
    MaxActive: 25,
    MaxIdle:   25,
    Wait:      true,
    Dial: func() (redis.Conn, error) {
        addr := fmt.Sprintf("localhost:%s", port)

        conn, err := redis.Dial("tcp", addr)
        if err != nil {
        return nil, err
        }

        return conn, nil
    },
}

redisWorker, err := redisw.New(
	WithPool(redisPool)
)

if err != nil {
    log.Fatal(err)
}

// Start the worker
go func() {
    err = redisWorker.Start()
}()

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option describes how options should be implemented.

func WithLogger

func WithLogger(l *zap.Logger) Option

WithLogger configures the logger option.

func WithMaxConcurrency

func WithMaxConcurrency(v int) Option

WithMaxConcurrency configures the maxConcurrency option.

func WithName

func WithName(name string) Option

WithName configures the name option.

func WithPool

func WithPool(p *redis.Pool) Option

WithPool configures the Pool option.

type Options

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

Options are used to configure the adapter config.

type Worker

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

Worker implements the Worker interface.

func New

func New(opts ...Option) (*Worker, error)

New returns a new instance of Worker with a predefined config.

func (*Worker) DeleteJob

func (*Worker) DeleteJob(_, _ string) error

DeleteJob removes a job from the queue.

func (*Worker) Perform

func (a *Worker) Perform(job worker.Job) (*worker.JobInfo, error)

Perform sends a new job to the queue, now.

func (*Worker) PerformAt

func (a *Worker) PerformAt(
	job worker.Job,
	t time.Time,
) (*worker.JobInfo, error)

PerformAt sends a new job to the queue, with a given start time.

func (*Worker) PerformIn

func (a *Worker) PerformIn(
	job worker.Job,
	t time.Duration,
) (*worker.JobInfo, error)

PerformIn sends a new job to the queue, with a given delay.

func (*Worker) Register

func (a *Worker) Register(name string, h worker.Handler) error

Register binds a new job, with a name and a handler.

func (*Worker) RegisterWithOptions

func (a *Worker) RegisterWithOptions(
	name string,
	opts work.JobOptions,
	h worker.Handler,
) error

RegisterWithOptions binds a new job, with a name, options and a handler.

func (*Worker) Start

func (a *Worker) Start() error

Start starts the adapter event loop.

func (*Worker) Stop

func (a *Worker) Stop() error

Stop stops the adapter event loop.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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