{"modulePath":"github.com/SolomonAIEngineering/backend-core-library","version":"v1.30.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package taskprocessor\n\n## Variables\n\n```go\nvar (\n\t// `ErrClientNotSet` is an error that is returned when the `client` property of the `TaskProcessor`\n\t// struct is not set.\n\tErrClientNotSet = errors.New(\"client not set\")\n\t// `ErrWorkerNotSet` is an error that is returned when the `worker` property of the `TaskProcessor`\n\t// struct is not set.\n\tErrWorkerNotSet = errors.New(\"worker not set\")\n\t// `ErrLoggerNotSet` is an error that is returned when the `logger` property of the `TaskProcessor`\n\t// struct is not set.\n\tErrLoggerNotSet = errors.New(\"logger not set\")\n\t// `ErrInstrumentationClientNotSet` is an error that is returned when the `instrumentationClient`\n\t// property of the `TaskProcessor` struct is not set.\n\tErrInstrumentationClientNotSet = errors.New(\"instrumentation client not set\")\n\t// `ErrConcurrencyFactorNotSet` is an error that is returned when the `concurrencyFactor`\n\t// property of the `TaskProcessor` struct is not set.\n\tErrConcurrencyFactorNotSet = errors.New(\"concurrently factor not set\")\n\t// `ErrTaskNotSet` is an error that is returned when the `task` argument of the `EnqueueTask` method\n\t// is not set.\n\tErrTaskNotSet = errors.New(\"task not set\")\n\t// `ErrTaskHandlerNotSet` is an error that is returned when the `taskHandler` property of the\n\t// `TaskProcessor` struct is not set.\n\tErrTaskHandlerNotSet = errors.New(\"task handler not set\")\n)\n```\n\n## Types\n\n```go\ntype IProcessor interface {\n\t// `Start() error` is a method of the `TaskProcessor` struct that starts the worker\n\t// to process tasks from the Asynq task queue as well as the scheduler process. It takes a `TaskProcessorHandler` function as an\n\t// argument, which is a function that will be called for each task that is processed by the worker. The\n\t// `TaskProcessorHandler` function takes a `context.Context` and an `*asynq.Task` as arguments, and\n\t// returns an error. The `Start` method returns an error if there is a problem starting the worker.\n\tStart() error\n\t// `Validate()` is a method of the `TaskProcessor` struct that checks if all the required properties of\n\t// the struct have been set. It returns an error if any of the required properties are not set,\n\t// indicating that the `TaskProcessor` is not ready to start processing tasks. This method is typically\n\t// called before starting the worker to ensure that all the necessary dependencies are in place.\n\tValidate() error\n\t// `EnqueueTask` is a method of the `TaskProcessor` struct that is used to enqueue a task in the Asynq\n\t// task queue. It takes a `context.Context`, an `*asynq.Task`, and an optional variadic argument of\n\t// `asynq.Option` as arguments. The `ctx` argument is a context that can be used to cancel the task or\n\t// set a timeout. The `task` argument is a pointer to an instance of the `asynq.Task` struct, which\n\t// contains information about the task to be executed, such as the task type, payload, and priority.\n\t// The `opts` argument is a variadic argument of `asynq.Option`, which can be used to set additional\n\t// options for the task, such as a delay or a custom queue name. The method returns an error if there\n\t// is a problem enqueueing the task in the Asynq task queue.\n\tEnqueueTask(ctx context.Context, task *asynq.Task, opts ...asynq.Option) (*asynq.TaskInfo, error)\n}\n```\nIProcessor is an interface that defines the methods that must be implemented by a task processor\n\n```go\ntype Option func(*TaskProcessor)\n```\nOption is a function that is used to set properties of the TaskProcessor struct\n\n```go\nfunc WithConcurrencyFactorOpt(concurrencyFactor *int) Option\n```\n\n```go\nfunc WithInstrumentationClientOpt(instrumentationClient *instrumentation.Client) Option\n```\n\n```go\nfunc WithLoggerOpt(logger *zap.Logger) Option\n```\n\n```go\nfunc WithRedisAddressOpt(redisAddress string) Option\n```\n\n```go\nfunc WithTaskHandlerOpt(taskHandler taskhandler.ITaskHandler) Option\n```\n\n```go\ntype ProcessingInterval string\n```\nProcessingInterval represents the various processing intervals for a recurring task\n\n```go\nconst (\n\tEveryYear          ProcessingInterval = \"@yearly\"\n\tEveryMonth         ProcessingInterval = \"@monthly\"\n\tEveryWeek          ProcessingInterval = \"@weekly\"\n\tEveryDayAtMidnight ProcessingInterval = \"@midnight\"\n\tEveryDay           ProcessingInterval = \"@daily\"\n\tEvery24Hours       ProcessingInterval = \"@every 24h\"\n\tEvery12Hours       ProcessingInterval = \"@every 12h\"\n\tEvery6Hours        ProcessingInterval = \"@every 6h\"\n\tEvery3Hours        ProcessingInterval = \"@every 3h\"\n\tEveryHour          ProcessingInterval = \"@every 1h\"\n\tEvery30Minutes     ProcessingInterval = \"@every 30m\"\n\tEvery15Minutes     ProcessingInterval = \"@every 15m\"\n\tEvery10Minutes     ProcessingInterval = \"@every 10m\"\n\tEvery5Minutes      ProcessingInterval = \"@every 5m\"\n\tEvery3Minutes      ProcessingInterval = \"@every 3m\"\n\tEvery1Minutes      ProcessingInterval = \"@every 1m\"\n\tEvery30Seconds     ProcessingInterval = \"@every 30s\"\n)\n```\n\n```go\nfunc (p ProcessingInterval) String() string\n```\nThe \\`String()\\` method is a method defined on the \\`ProcessingInterval\\` type. It is used to convert a \\`ProcessingInterval\\` value to its corresponding string representation.\n\n```go\ntype TaskProcessor struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc NewTaskProcessor(opts ...Option) (*TaskProcessor, error)\n```\nNewTaskProcessor creates a new TaskProcessor instance \\`\\`\\`go tp, err := NewTaskProcessor(\n\n\tWithInstrumentationClient(ic),\n\tWithLogger(logger),\n\tWithRedisConnectionAddress(\"localhost:6379\"),\n\tWithConcurrencyFactor(10),\n\n)\n\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tdefer tp.Close()\n\t// start the worker asynchronously\n\tgo func() {\n\t\tif err := tp.Start(handler); err != nil {\n\t\t\tlog.Fatal(err)\n\t\t}\n\n\\`\\`\\`\n\n```go\nfunc (tp *TaskProcessor) Close() error\n```\nClose closes the task processor\n\n\\`\\`\\`go\n\n\t\t\ttp, err := NewTaskProcessor(...opts)\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\n\t\t\tdefer tp.Close()\n\t     \t// start the worker asynchronously in another go routine\n\t\t \tgo func(fn TaskProcessorHandler) {\n\t\t\t\ttp.Start(fn)\n\t\t\t}(fn)\n\n\\`\\`\\`\n\n```go\nfunc (tp *TaskProcessor) EnqueueRecurringTask(ctx context.Context, task *asynq.Task, interval ProcessingInterval, opts ...asynq.Option) (*string, error)\n```\nThe \\`EnqueueRecurringTask\\` function is used to enqueue a recurring task with a specified interval. It takes in the context, the task to be enqueued, the interval at which the task should be repeated, and optional options for the task. It returns a pointer to a string representing the entry ID of the recurring task and an error if any.\n\n```go\nfunc (tp *TaskProcessor) EnqueueTask(ctx context.Context, task *asynq.Task, opts ...asynq.Option) (*asynq.TaskInfo, error)\n```\nEnqueueTask implements IProcessor.\n\n```go\nfunc (tp *TaskProcessor) Start() error\n```\nStart starts the task processor worker as well as the scheduler \\`\\`\\`go\n\n\t\t\ttp, err := NewTaskProcessor(...opts)\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\n\t     \t// start the worker asynchronously in another go routine\n\t\t \tgo tp.Start()\n\n\\`\\`\\`\n\n```go\nfunc (tp *TaskProcessor) Validate() error\n```\nValidate validates the task processor\n\n```go\ntype TaskProcessorHandler func(context.Context, *asynq.Task) error\n```\n\\`TaskProcessorHandler\\` is a type alias for a function that processes a task. This function is used by the \\`TaskProcessor\\` to process tasks from the Asynq task queue.\n\n","path":"github.com/SolomonAIEngineering/backend-core-library/task-processor","name":"taskprocessor","synopsis":"","isRedistributable":true}
