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 Options
- 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 (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 TaskRunOptions
- type TasqOps
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultTaskQConfig ¶
DefaultTaskQConfig will return a QueueOptions with specified name and functional options applied
Types ¶
type CronJob ¶
type CronJob struct { Handler CronJobHandler Period time.Duration }
CronJob definition, params reduced to the minimum, all required
type CronJobHandler ¶
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 Options ¶
type Options func(c *options)
Options allow functional options to be supplied
func WithLogger ¶
WithLogger will set the custom logger interface
func WithTaskqConfig ¶
func WithTaskqConfig(config *taskq.QueueOptions) Options
WithTaskqConfig will set the taskq custom config
type TaskEngine ¶
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 }
TaskEngine is the taskmanager client interface
func NewTaskManager ¶
func NewTaskManager(ctx context.Context, opts ...Options) (TaskEngine, error)
NewTaskManager creates a new client for all TaskManager functionality If no options are given, it will use local memory for the queue.
type TaskManager ¶
type TaskManager struct {
// contains filtered or unexported fields
}
TaskManager implements the TaskEngine interface
func (*TaskManager) Close ¶
func (tm *TaskManager) Close(ctx context.Context) error
Close the client and any open connections
func (*TaskManager) CronJobsInit ¶
func (tm *TaskManager) CronJobsInit(cronJobsMap CronJobs) (err error)
CronJobsInit registers and runs the cron jobs
func (*TaskManager) Factory ¶
func (tm *TaskManager) Factory() Factory
Factory will return the factory that is set
func (*TaskManager) RegisterTask ¶
func (c *TaskManager) RegisterTask(name string, handler interface{}) (err error)
RegisterTask will register a new task to handle asynchronously
func (*TaskManager) ResetCron ¶
func (tm *TaskManager) ResetCron()
ResetCron will reset the cron scheduler and all loaded tasks
func (*TaskManager) RunTask ¶
func (c *TaskManager) RunTask(ctx context.Context, options *TaskRunOptions) error
RunTask will run a task using TaskQ
func (*TaskManager) Tasks ¶
func (tm *TaskManager) Tasks() map[string]*taskq.Task
Tasks will return the list of tasks
type TaskRunOptions ¶
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