feat(rabbitmq): Add tasks for processing
This commit is contained in:
42
modules/queue/tasks/tasks.go
Normal file
42
modules/queue/tasks/tasks.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package tasks
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.ostiwe.com/ostiwe-com/status/modules/log"
|
||||
)
|
||||
|
||||
var (
|
||||
DefaultFallbackFn = func(_ context.Context, _ error) (bool, error) {
|
||||
log.Global.Get(log.QUEUE).Info("Default fallback function triggered")
|
||||
|
||||
return true, nil
|
||||
}
|
||||
DefaultAfterHandleFn = func(_ context.Context, _ []byte) error {
|
||||
log.Global.Get(log.QUEUE).Info("Default after handler function triggered")
|
||||
|
||||
return nil
|
||||
}
|
||||
)
|
||||
|
||||
// Task represents a task that can be executed in the queue.
|
||||
//
|
||||
// Name returns the name of the task, used for logging and identification purposes.
|
||||
//
|
||||
// Handle processes a message from the queue. It takes a context and the raw message body ([]byte) as arguments.
|
||||
// If handling fails, it should return an error that can be caught in the Fallback method.
|
||||
//
|
||||
// AfterHandle performs some action after successfully processing the message with Handle.
|
||||
// It takes the same arguments as Handle: a context and the raw message body ([]byte).
|
||||
// Default is DefaultAfterHandleFn
|
||||
//
|
||||
// Fallback handles errors that occur during the execution of the Handle method.
|
||||
// It takes a context and an error as arguments. The method should return a boolean indicating whether the error was handled,
|
||||
// and error for additional logging or debugging information.
|
||||
// Default is DefaultFallbackFn
|
||||
type Task struct {
|
||||
Name string
|
||||
Handle func(ctx context.Context, msgBody []byte) error
|
||||
AfterHandle func(ctx context.Context, msgBody []byte) error
|
||||
Fallback func(ctx context.Context, err error) (bool, error)
|
||||
}
|
||||
Reference in New Issue
Block a user