util

package
v1.0.1-0...-7ff242b Latest Latest
Warning

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

Go to latest
Published: May 15, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LowPriorityQueue  string = "low_priority_queue"
	HighPriorityQueue string = "high_priority_queue"

	QueueModeLazy    string = "lazy"
	QueueModeDefault string = "default"
)

Some string constants with queue priority and queue mode

Variables

View Source
var NoOpLogger = noOpLogger{}

NoOpLogger is no operation logger

Functions

func GenerateRandStr

func GenerateRandStr(l int) string

GenerateRandStr generates random string

func NewHeaderContext

func NewHeaderContext(ctx context.Context, header Header) context.Context

NewHeaderContext returns header context

Types

type Handler

type Handler interface {
	Do(ctx context.Context, payload []byte) error
}

Handler is the task handler struct interface

type HandlerFunc

type HandlerFunc func(ctx context.Context, payload []byte) error

HandlerFunc is a task handler function type

func (HandlerFunc) Do

func (h HandlerFunc) Do(ctx context.Context, payload []byte) error

Do actually does the work

type Header http.Header

Header is http header

func HeaderFromContext

func HeaderFromContext(ctx context.Context) Header

HeaderFromContext returns header from context

func (Header) Add

func (h Header) Add(key, val string)

Add adds a header value

func (Header) All

func (h Header) All(key string) []string

All returns all headers

func (Header) Get

func (h Header) Get(key string) string

Get gets header value

func (Header) Set

func (h Header) Set(key, val string)

Set sets header value

type LogLevel

type LogLevel uint8

LogLevel holds log level values

const (
	LogLevelError LogLevel = iota
	LogLevelWarn
	LogLevelInfo
	LogLevelDebug
	LogLevelTrace
)

LogLevel is levels of logs

func (LogLevel) String

func (l LogLevel) String() string

type Logger

type Logger interface {
	Error(msg string, err error, objects ...Object)
	Debug(msg string, objects ...Object)
	Info(msg string, objects ...Object)
	Warn(msg string, objects ...Object)
}

Logger is the logs interface

type Object

type Object struct {
	Key string
	Val interface{}
}

Object is a basic key value object

type Status

type Status string

Status is the status of the task

const (
	StatusRetry      Status = "retry"
	StatusInitiated  Status = "initiated"
	StatusQueued     Status = "queued"
	StatusInProgress Status = "in_progress"
	StatusFailed     Status = "failed"
	StatusSuccess    Status = "success"
)

list of task status

func (Status) CheckStatusOrder

func (p Status) CheckStatusOrder(st Status) bool

CheckStatusOrder check if status st can be updated by status p

type StdLogger

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

StdLogger holds a log

func NewLogger

func NewLogger() StdLogger

NewLogger returns a new standard logger

func (StdLogger) Debug

func (l StdLogger) Debug(msg string, objects ...Object)

Debug prints debug logs

func (StdLogger) Error

func (l StdLogger) Error(msg string, err error, objects ...Object)

Error prints error logs

func (StdLogger) Info

func (l StdLogger) Info(msg string, objects ...Object)

Info prints info logs

func (StdLogger) Warn

func (l StdLogger) Warn(msg string, objects ...Object)

Warn prints warning logs

type Task

type Task struct {
	TaskID         string
	PrimaryKey     string
	Name           string
	OriginalTaskID string
	Retry          int
	Payload        []byte
	Priority       TaskPriority
	Status         Status
	FailError      string
	Duration       *float64
	CreatedAt      time.Time
	UpdatedAt      time.Time
}

Task field hold the necessary field

type TaskDateRangeCount

type TaskDateRangeCount struct {
	ID              time.Time
	Total           int
	CountRetry      int
	CountInitiated  int
	CountQueued     int
	CountInProgress int
	CountSuccess    int
	CountFailed     int
}

TaskDateRangeCount holds necessary values for task and it's statuses in a date range

type TaskPriority

type TaskPriority string

TaskPriority is the priority of the task

var (
	TaskPriorityHigh TaskPriority = "High"
	TaskPriorityLow  TaskPriority = "Low"
)

list of TaskPriority

func (TaskPriority) Valid

func (p TaskPriority) Valid() bool

Valid check the task priority

type Worker

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

Worker hold the necessary field of task handler

func NewWorker

func NewWorker(name string, h Handler) *Worker

NewWorker return a new worker instance

func (*Worker) Handler

func (w *Worker) Handler() Handler

Handler return task handler

func (*Worker) Name

func (w *Worker) Name() string

Name return worker name

func (*Worker) Process

func (w *Worker) Process(msg *amqp.Delivery) error

Process call do method of task handler

Jump to

Keyboard shortcuts

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