workr

package module
v0.0.0-...-8fa57b2 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

README

WORKR

Async distributed worker jobs with redis as backend supporting scheduling.

Dev stage, do not use in production

License

This SDK is distributed under the Apache License, Version 2.0, see LICENSE and NOTICE for more information.

Documentation

Overview

Package workr ...

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewZ

func NewZ(score float64, member interface{}) *redis.Z

NewZ returns a redis Z type

Types

type Config

type Config struct {
	Concurrency    int
	RedisHost      string
	RedisPort      int
	RedisPassword  string
	RedisDB        int
	RedisQueueName string
	Logger         *zap.Logger
}

Config for workr

func (*Config) SetDefaults

func (cfg *Config) SetDefaults()

SetDefaults on config

type Job

type Job interface {
	Name() string
	New() Job
	Run(*Workr) error
	Bytes() ([]byte, error)
	Load(data []byte) error
}

Job represent a job

type QueueItem

type QueueItem struct {
	JobName string `json:"n"`
	Data    []byte `json:"d"`
}

QueueItem represent an item in the queue

func (*QueueItem) Bytes

func (itm *QueueItem) Bytes() ([]byte, error)

Bytes return json bytes for queueItem

func (*QueueItem) Load

func (itm *QueueItem) Load(data []byte) error

Load load data bytes to *QueueItem itm

type Workr

type Workr struct {
	Config      *Config
	RedisClient *redis.Client
	// contains filtered or unexported fields
}

Workr define main worker instance

func New

func New(cfg *Config) (*Workr, error)

New workr with config cfg

func (*Workr) Now

func (wrkr *Workr) Now(jj Job) error

Now run job now

func (*Workr) Pop

func (wrkr *Workr) Pop() (*QueueItem, error)

Pop job from queue

func (*Workr) RedisConnect

func (wrkr *Workr) RedisConnect() error

RedisConnect connect to redis and ping it

func (*Workr) Register

func (wrkr *Workr) Register(jj Job)

Register a job

func (*Workr) Schedule

func (wrkr *Workr) Schedule(at time.Time, jj Job) error

Schedule a job at defined time

func (*Workr) Shutdown

func (wrkr *Workr) Shutdown(ctx context.Context) error

Shutdown workr @TODO: handle running jobs end

func (*Workr) Work

func (wrkr *Workr) Work()

Work warch for jobs, blocking

Jump to

Keyboard shortcuts

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