Documentation ¶
Overview ¶
Package taskmanager is the task/job management service layer for concurrent and asynchronous tasks with cron scheduling.
Index ¶
- func DefaultTaskQConfig(name string, opts ...TasqOps) *taskq.QueueOptions
- type CronJob
- type CronJobHandler
- type CronJobs
- type Factory
- type TaskEngine
- type TaskManager
- func (tm *TaskManager) Close(ctx context.Context) error
- func (tm *TaskManager) CronJobsInit(cronJobsMap CronJobs) (err error)
- func (tm *TaskManager) Factory() Factory
- func (tm *TaskManager) GetTxnCtx(ctx context.Context) context.Context
- func (tm *TaskManager) IsNewRelicEnabled() bool
- func (c *TaskManager) RegisterTask(name string, handler interface{}) (err error)
- func (tm *TaskManager) ResetCron()
- func (c *TaskManager) RunTask(ctx context.Context, options *TaskRunOptions) error
- func (tm *TaskManager) Tasks() map[string]*taskq.Task
- type TaskManagerOptions
- type TaskRunOptions
- type TasqOps
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
CronJobHandler is the handler for a cron job
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
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
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