workers

package
v0.0.0-...-e66c200 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2025 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EventContext

type EventContext struct {
	UserID    string                 `json:"user_id,omitempty"` // UUID as string for JSON
	PostID    int64                  `json:"post_id,omitempty"`
	CommentID int64                  `json:"comment_id,omitempty"`
	ChannelID int64                  `json:"channel_id,omitempty"`
	Action    string                 `json:"action,omitempty"`   // "create", "update", "delete", "view"
	Keywords  []string               `json:"keywords,omitempty"` // Searchable terms
	Metadata  map[string]interface{} `json:"metadata,omitempty"` // Additional context
	IPAddress string                 `json:"ip_address,omitempty"`
	UserAgent string                 `json:"user_agent,omitempty"`
	Path      string                 `json:"path,omitempty"`
}

EventContext represents structured context for searchable logging

func (*EventContext) ToJSON

func (ec *EventContext) ToJSON() string

ToJSON converts EventContext to JSON string for database storage

type ImageJob

type ImageJob struct {
	ID       string           // Unique job ID
	FilePath string           // Path to uploaded image
	UserID   models.UUIDField // User who uploaded the image
	PostID   int64            // Associated post ID (if applicable)
}

ImageJob represents a single image processing task

type ImageWorkerPool

type ImageWorkerPool struct {
	// contains filtered or unexported fields
}

ImageWorkerPool manages a pool of worker goroutines that process image jobs

func NewImageWorkerPool

func NewImageWorkerPool(workers, queueSize int, db *sql.DB) *ImageWorkerPool

NewImageWorkerPool creates a new worker pool workers: number of concurrent worker goroutines queueSize: maximum number of jobs that can be queued db: database connection for storing image metadata (can be nil for tests)

func (*ImageWorkerPool) QueueCapacity

func (pool *ImageWorkerPool) QueueCapacity() int

QueueCapacity returns the maximum queue size

func (*ImageWorkerPool) QueueLength

func (pool *ImageWorkerPool) QueueLength() int

QueueLength returns the current number of jobs in the queue

func (*ImageWorkerPool) Shutdown

func (pool *ImageWorkerPool) Shutdown(ctx context.Context) error

Shutdown gracefully shuts down the worker pool Waits for all workers to finish processing current jobs Returns error if context times out before workers finish

func (*ImageWorkerPool) Start

func (pool *ImageWorkerPool) Start()

Start starts the worker pool

func (*ImageWorkerPool) Stats

func (pool *ImageWorkerPool) Stats() PoolStats

func (*ImageWorkerPool) Submit

func (pool *ImageWorkerPool) Submit(job ImageJob) error

Submit submits a job to the worker pool Returns an error if the queue is full or pool is shut down

type LogEntry

type LogEntry struct {
	Type         string // "request", "error", "metric"
	RequestLog   *models.RequestLog
	ErrorLog     *models.ErrorLog
	SystemMetric *models.SystemMetric
}

LogEntry represents a log entry to be written to the database

type LoggerPool

type LoggerPool struct {
	// contains filtered or unexported fields
}

LoggerPool manages a pool of worker goroutines that write logs to the database

func NewLoggerPool

func NewLoggerPool(workers, queueSize int, db *sql.DB) *LoggerPool

NewLoggerPool creates a new logger worker pool workers: number of concurrent worker goroutines queueSize: maximum number of log entries that can be queued db: database connection for storing logs (can be nil for tests)

func (*LoggerPool) LogApplicationError

func (pool *LoggerPool) LogApplicationError(err error, userID models.UUIDField, path string, operation string, entityIDs map[string]interface{}) error

LogApplicationError logs structured error with full context

func (*LoggerPool) LogChannelJoined

func (pool *LoggerPool) LogChannelJoined(userID models.UUIDField, channelID int64, channelName string) error

LogChannelJoined logs when a user joins a channel

func (*LoggerPool) LogCommentCreated

func (pool *LoggerPool) LogCommentCreated(userID models.UUIDField, commentID int64, postID int64, contentLength int) error

LogCommentCreated logs when a user creates a comment

func (*LoggerPool) LogError

func (pool *LoggerPool) LogError(log models.ErrorLog) error

LogError submits an error log entry

func (*LoggerPool) LogMetric

func (pool *LoggerPool) LogMetric(metric models.SystemMetric) error

LogMetric submits a system metric entry

func (*LoggerPool) LogPostCreated

func (pool *LoggerPool) LogPostCreated(userID models.UUIDField, postID int64, channelID int64, title string, tags []string) error

LogPostCreated logs when a user creates a post

func (*LoggerPool) LogPostViewed

func (pool *LoggerPool) LogPostViewed(userID models.UUIDField, postID int64, channelID int64) error

LogPostViewed logs when a user views a post

func (*LoggerPool) LogReaction

func (pool *LoggerPool) LogReaction(userID models.UUIDField, postID int64, reactionType string) error

LogReaction logs when a user reacts to content

func (*LoggerPool) LogRequest

func (pool *LoggerPool) LogRequest(log models.RequestLog) error

LogRequest submits a request log entry

func (*LoggerPool) LogSearchQuery

func (pool *LoggerPool) LogSearchQuery(userID models.UUIDField, query string, resultCount int) error

LogSearchQuery logs search queries for analytics

func (*LoggerPool) LogUserLogin

func (pool *LoggerPool) LogUserLogin(userID models.UUIDField, username string, ipAddress string, userAgent string) error

LogUserLogin logs successful user authentication

func (*LoggerPool) Shutdown

func (pool *LoggerPool) Shutdown(ctx context.Context) error

Shutdown gracefully shuts down the logger pool Waits for all workers to finish writing pending logs Returns error if context times out before workers finish

func (*LoggerPool) Start

func (pool *LoggerPool) Start()

Start starts the logger worker pool

func (*LoggerPool) Stats

func (pool *LoggerPool) Stats() LoggerStats

func (*LoggerPool) Submit

func (pool *LoggerPool) Submit(entry LogEntry) error

Submit submits a log entry to the worker pool Returns an error if the queue is full or pool is shut down

type LoggerStats

type LoggerStats struct {
	Workers       int
	QueueLength   int
	QueueCapacity int
	QueueUsage    float64 // Percentage of queue used (0.0 to 1.0)
	DroppedLogs   int64
}

Stats returns statistics about the logger pool

type PoolStats

type PoolStats struct {
	Workers       int
	QueueLength   int
	QueueCapacity int
	QueueUsage    float64 // Percentage of queue used (0.0 to 1.0)
}

Stats returns statistics about the worker pool

Jump to

Keyboard shortcuts

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