redis

package
v1.2.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 6, 2026 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EmailQueueName      = "email_queue"
	EmailQueueDeadName  = "email_queue_dead"
	EmailQueueRetryName = "email_queue_retry"
	EmailSentLogName    = "email_sent_log"
	EmailErrorLogName   = "email_error_log"
	WebhookQueueName    = "webhook_queue"
	WebhookDeadName     = "webhook_queue_dead"
	TelegramQueueName   = "telegram_queue"
	TelegramDeadName    = "telegram_queue_dead"
)

Variables

View Source
var (
	RDB    *goredis.Client
	Ctx    = context.Background()
	Prefix string
)
View Source
var EmailWorkerConfigFn func() EmailWorkerConfig
View Source
var RateLimitConfigFn func() RateLimitConfig

Functions

func Ack

func Ack(queueName string, payload []byte) error

func ActiveAddr

func ActiveAddr() string

func Allow

func Allow(key string, limit int, window time.Duration) (bool, int, error)

func AllowPublic

func AllowPublic(key string) (bool, int, error)

func ClearQueue

func ClearQueue(queueName string) (int64, error)

func Client

func Client() *goredis.Client

func Close

func Close()

func Configure

func Configure(o Options)

func CurrentPrefix

func CurrentPrefix() string

func DeleteDeadLetter

func DeleteDeadLetter(itemToFind string) (int64, error)

func Dequeue

func Dequeue(queueName string, timeout time.Duration) ([]byte, bool, error)

func DequeueReliable

func DequeueReliable(queueName string, timeout time.Duration) ([]byte, bool, error)

func Diagnostics

func Diagnostics() string

func Enqueue

func Enqueue(queueName string, task interface{}) error

func EnqueueWebhook

func EnqueueWebhook(provider, eventType string, event map[string]interface{}, payload string) error

func EnsureInitialized

func EnsureInitialized(component string) error

func Init

func Init(addrOverride string)

func IsReady

func IsReady() bool

func Key

func Key(name string) string

func LogErr

func LogErr(what string, cmd interface{ Err() error })

func ProcessOneFromQueue

func ProcessOneFromQueue(queueName string, senderFunc func(string, string, string, interface{}) error) (bool, error)

func ProcessingName

func ProcessingName(queueName string) string

func PushDeadLetter

func PushDeadLetter(queueName string, payload []byte) error

func Reconnect

func Reconnect(reason error) error

func RecordEmailError

func RecordEmailError(task EmailTask, attempt int, sendErr error)

func RecordEmailSent

func RecordEmailSent(task EmailTask, attempts int)

func RecoverProcessing

func RecoverProcessing(queueName string) (int, error)

func RequeueDeadLetter

func RequeueDeadLetter() (bool, error)

func StartEmailWorker

func StartEmailWorker(send func(EmailTask) error, permanent func(error) bool)

Types

type EmailAttachment

type EmailAttachment struct {
	Filename      string `json:"filename"`
	ContentType   string `json:"content_type"`
	Data          []byte `json:"data,omitempty"`
	ContentBase64 string `json:"content_base64,omitempty"`
}

func NewEmailAttachment

func NewEmailAttachment(filename, contentType string, content []byte) EmailAttachment

func (EmailAttachment) Bytes

func (a EmailAttachment) Bytes() ([]byte, error)

type EmailDeliveryState

type EmailDeliveryState struct {
	Status string
	Detail string
}

func EmailDeliveryStatus

func EmailDeliveryStatus(toEmail, templateName string, since time.Time) EmailDeliveryState

type EmailErrorRecord

type EmailErrorRecord struct {
	Timestamp    string `json:"ts"`
	ToEmail      string `json:"to_email"`
	Subject      string `json:"subject"`
	TemplateName string `json:"template_name"`
	Attempt      int    `json:"attempt"`
	Error        string `json:"error"`
	RawTask      string `json:"raw_task,omitempty"`
}

type EmailSentRecord

type EmailSentRecord struct {
	Timestamp    string `json:"ts"`
	ToEmail      string `json:"to_email"`
	Subject      string `json:"subject"`
	TemplateName string `json:"template_name"`
	Attempts     int    `json:"attempts"`
}

type EmailTask

type EmailTask struct {
	ToEmail      string
	Subject      string
	TemplateName string
	Data         interface{}
	Attachments  []EmailAttachment `json:"attachments,omitempty"`
	OrderID      string            `json:"order_id,omitempty"`
	QueuedAt     string            `json:"queued_at,omitempty"`
	Attempts     int               `json:"attempts,omitempty"`
	RawJSON      string            `json:"-"`
}

func InspectQueue

func InspectQueue(queueName string) ([]EmailTask, error)

func (EmailTask) MailerAttachments

func (t EmailTask) MailerAttachments() ([]mailer.Attachment, error)

type EmailWorkerConfig

type EmailWorkerConfig struct {
	Workers   int
	PerSecond float64
}

type Options

type Options struct {
	Settings      func() (Settings, error)
	DefaultPrefix string
}

type RateLimitConfig

type RateLimitConfig struct {
	Limit     int
	Window    time.Duration
	Whitelist []string
}

type Settings

type Settings struct {
	Addr     string
	Password string
	DB       int
	Prefix   string
}

type TelegramTask

type TelegramTask struct {
	ChatID     string    `json:"chat_id"`
	Message    string    `json:"message"`
	ParseMode  string    `json:"parse_mode"`
	EnqueuedAt time.Time `json:"enqueued_at"`
	Attempts   int       `json:"attempts"`
	MaxRetries int       `json:"max_retries"`
	BotRef     string    `json:"bot_ref,omitempty"`
}

type WebhookJob

type WebhookJob struct {
	ID         string                 `json:"id"`
	Provider   string                 `json:"provider"`
	EventType  string                 `json:"event_type"`
	Event      map[string]interface{} `json:"event"`
	Payload    string                 `json:"payload"`
	EnqueuedAt time.Time              `json:"enqueued_at"`
	Attempts   int                    `json:"attempts"`
	MaxRetries int                    `json:"max_retries"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL