Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrHandleCronFailed = errors.New("failed to handle cron") ErrServerStartFailed = errors.New("failed to start the worker server") ErrClientStartFailed = errors.New("failed to start the worker client") ErrTaskPatternInvalid = errors.New("task pattern is invalid") ErrCronSpecInvalid = errors.New("cron specification is invalid") ErrSubmitFailed = errors.New("failed to submit the payload") )
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client interface { // Submit sends a payload to be processed by the task handler registered with the specified pattern. // The task will be executed immediately if it matches the pattern. // // It returns an error if the pattern is invalid or if there is an issue submitting the task. Submit(ctx context.Context, pattern TaskPattern, payload []byte) error // SubmitToBatch sends a payload to be added to a batch for processing. The task handler registered with // the specified pattern will process the batch either when a series of payloads have been enqueued // or when the specified time delay is reached. // // It returns an error if the pattern is invalid or if there is an issue submitting the task to the batch. SubmitToBatch(ctx context.Context, pattern TaskPattern, payload []byte) error // Close closes the client's connection. Close() error }
Client represents a client that submits tasks to be handled by the server.
type CronHandler ¶
type CronSpec ¶
type CronSpec string
func (CronSpec) MustValidate ¶
func (cs CronSpec) MustValidate()
MustValidate is similar to CronSpec.Validate but panics when invalid.
type Cronjob ¶
type Cronjob struct { // Identifier is a UUID for the cron job, used internally to register the task with the // scheduler. Identifier string // Spec is the cron expression that defines the schedule for the cron job. Spec CronSpec // Handler is the callback function that will be executed when the cron specification is met. Handler CronHandler // Unique defines whether the task cannot be perfomed concurrently. Unique bool }
type CronjobOption ¶ added in v0.17.2
type CronjobOption func(c *Cronjob)
type Server ¶
type Server interface { // HandleTask registers a task with the provided pattern. The task will be executed // every time a client enqueues a payload matching the pattern. Batch tasks will be executed // when the client enqueues a series of payloads or when the specified time delay is reached. // // It panics if the pattern is invalid. Batch tasks are specified in options. HandleTask(pattern TaskPattern, cb TaskHandler, opts ...TaskOption) // HandleCron executes the cronFunc every time the cron specification is met. // // It panics if the cron specification is invalid. HandleCron(spec CronSpec, cronFunc CronHandler, opts ...CronjobOption) // Start initializes and starts the worker in a non-blocking manner. The server is // turned off whedn the context was done. // // It returns an error if any issues occur during the startup process. Start() error // Shutdown gracefully shuts down the server. Shutdown() }
Server represents a process that handles tasks and cronjobs. A Client can submit tasks.
type Task ¶
type Task struct { // Pattern is a string to which the task can listen to message/events. Pattern TaskPattern // Handler is the callback that the task will execute when receiving messages/events. Handler TaskHandler }
type TaskOption ¶
type TaskOption func(t *Task)
type TaskPattern ¶
type TaskPattern string
TaskPattern represents a pattern to which a task can register to listen. It must be in the format "queue:kind".
func (TaskPattern) MustValidate ¶
func (tp TaskPattern) MustValidate()
MustValidate is similar to TaskPattern.Validate but panics when invalid.
func (TaskPattern) Queue ¶
func (tp TaskPattern) Queue() string
Queue returns the queue component of the pattern.
func (TaskPattern) String ¶
func (tp TaskPattern) String() string
func (TaskPattern) Validate ¶
func (tp TaskPattern) Validate() bool
Validate reports whether the pattern is valid or not.
Click to show internal directories.
Click to hide internal directories.