taskmanager

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2024 License: Apache-2.0 Imports: 14 Imported by: 3

Documentation

Overview

Package taskmanager is the task/job management service layer for concurrent and asynchronous tasks with cron scheduling.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultTaskQConfig

func DefaultTaskQConfig(name string, opts ...TasqOps) *taskq.QueueOptions

DefaultTaskQConfig will return a QueueOptions with specified name and functional options applied

Types

type CronJob added in v0.8.0

type CronJob struct {
	Handler CronJobHandler
	Period  time.Duration
}

CronJob definition, params reduced to the minimum, all required

type CronJobHandler added in v0.8.0

type CronJobHandler func(ctx context.Context) error

CronJobHandler is the handler for a cron job

type CronJobs added in v0.8.0

type CronJobs map[string]CronJob

CronJobs as a map prevents duplicate jobs with the same name

type Factory

type Factory string

Factory is the different types of task factories that are supported

const (
	FactoryEmpty  Factory = "empty"
	FactoryMemory Factory = "memory"
	FactoryRedis  Factory = "redis"
)

Supported factories

func (Factory) IsEmpty

func (f Factory) IsEmpty() bool

IsEmpty will return true if the factory is not set

func (Factory) String

func (f Factory) String() string

String is the string version of factory

type TaskEngine added in v0.9.0

type TaskEngine interface {
	RegisterTask(name string, handler interface{}) error
	ResetCron()
	RunTask(ctx context.Context, options *TaskRunOptions) error
	Tasks() map[string]*taskq.Task
	CronJobsInit(cronJobsMap CronJobs) error
	Close(ctx context.Context) error
	Factory() Factory
	GetTxnCtx(ctx context.Context) context.Context
	IsNewRelicEnabled() bool
}

TaskEngine is the taskmanager client interface

func NewTaskManager added in v0.9.0

func NewTaskManager(ctx context.Context, opts ...TaskManagerOptions) (TaskEngine, error)

NewTaskManager creates a new client for all TaskManager functionality If no options are given, it will use local memory for the queue. ctx may contain a NewRelic txn (or one will be created)

type TaskManager added in v0.9.0

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

TaskManager implements the TaskEngine interface

func (*TaskManager) Close added in v0.9.0

func (tm *TaskManager) Close(ctx context.Context) error

Close the client and any open connections

func (*TaskManager) CronJobsInit added in v0.9.0

func (tm *TaskManager) CronJobsInit(cronJobsMap CronJobs) (err error)

CronJobsInit registers and runs the cron jobs

func (*TaskManager) Factory added in v0.9.0

func (tm *TaskManager) Factory() Factory

Factory will return the factory that is set

func (*TaskManager) GetTxnCtx added in v0.9.0

func (tm *TaskManager) GetTxnCtx(ctx context.Context) context.Context

GetTxnCtx will check for an existing transaction

func (*TaskManager) IsNewRelicEnabled added in v0.9.0

func (tm *TaskManager) IsNewRelicEnabled() bool

IsNewRelicEnabled will return if new relic is enabled

func (*TaskManager) RegisterTask added in v0.9.0

func (c *TaskManager) RegisterTask(name string, handler interface{}) (err error)

RegisterTask will register a new task to handle asynchronously

func (*TaskManager) ResetCron added in v0.9.0

func (tm *TaskManager) ResetCron()

ResetCron will reset the cron scheduler and all loaded tasks

func (*TaskManager) RunTask added in v0.9.0

func (c *TaskManager) RunTask(ctx context.Context, options *TaskRunOptions) error

RunTask will run a task using TaskQ

func (*TaskManager) Tasks added in v0.9.0

func (tm *TaskManager) Tasks() map[string]*taskq.Task

Tasks will return the list of tasks

type TaskManagerOptions added in v0.9.0

type TaskManagerOptions func(c *options)

TaskManagerOptions allow functional options to be supplied

func WithLogger

func WithLogger(customLogger *zerolog.Logger) TaskManagerOptions

WithLogger will set the custom logger interface

func WithNewRelic

func WithNewRelic() TaskManagerOptions

WithNewRelic will enable the NewRelic wrapper

func WithTaskqConfig added in v0.9.0

func WithTaskqConfig(config *taskq.QueueOptions) TaskManagerOptions

WithTaskqConfig will set the taskq custom config

type TaskRunOptions added in v0.9.0

type TaskRunOptions struct {
	Arguments      []interface{} // Arguments for the task
	RunEveryPeriod time.Duration // Cron job!
	TaskName       string        // Name of the task
}

TaskRunOptions are the options for running a task

type TasqOps added in v0.9.0

type TasqOps func(*taskq.QueueOptions)

TasqOps allow functional options to be supplied

func WithRedis added in v0.9.0

func WithRedis(addr string) TasqOps

WithRedis will set the redis client for the TaskQ engine Note: Because we use redis/v8, we need to use Redis lower than 7.2.0

Jump to

Keyboard shortcuts

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