queue

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	QueuePendingKey = "ares:queue:pending"
	QueueRunningKey = "ares:queue:running"
	QueueFailedKey  = "ares:queue:failed"
)

Queue names (keys in Redis)

Variables

This section is empty.

Functions

This section is empty.

Types

type QueueManager

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

QueueManager: Manages job queues with priority support Uses Redis sorted sets for efficient priority queue operations Complexity: O(log n) for enqueue, O(log n) for dequeue

func NewQueueManager

func NewQueueManager(redisClient *redis.RedisClient) *QueueManager

NewQueueManager: Create a new queue manager

func (*QueueManager) ClearQueue

func (qm *QueueManager) ClearQueue(ctx context.Context, queueKey string) error

ClearQueue: Clear all jobs from a queue (dangerous - use carefully)

func (*QueueManager) DequeueJobByID

func (qm *QueueManager) DequeueJobByID(ctx context.Context, jobID string) (*common.Job, error)

DequeueJobByID: Get a specific job by ID and remove it from pending queue Useful for: canceling a job, moving to running queue, etc.

func (*QueueManager) DequeueNextJob

func (qm *QueueManager) DequeueNextJob(ctx context.Context) (*common.Job, error)

DequeueNextJob: Get the next job to schedule (highest priority, oldest within priority) Returns: (job, error) Atomic operation: removes from queue and returns job CORRECTED: ZPopMin returns map[string]float64, not slice

func (*QueueManager) EnqueuePendingJob

func (qm *QueueManager) EnqueuePendingJob(ctx context.Context, job *common.Job) error

EnqueuePendingJob: Add a job to the pending queue Score = -priority + timestamp/1e10 (sorts by priority desc, then by time asc) This ensures: high priority jobs first, then FIFO within same priority

func (*QueueManager) GetFailedJobCount

func (qm *QueueManager) GetFailedJobCount(ctx context.Context) (int64, error)

GetFailedJobCount: Get number of jobs in failed queue

func (*QueueManager) GetPendingJobCount

func (qm *QueueManager) GetPendingJobCount(ctx context.Context) (int64, error)

GetPendingJobCount: Get number of jobs in pending queue

func (*QueueManager) GetPendingJobs

func (qm *QueueManager) GetPendingJobs(ctx context.Context, limit int) ([]*common.Job, error)

GetPendingJobs: Get top N pending jobs (for debugging)

func (*QueueManager) GetRunningJobCount

func (qm *QueueManager) GetRunningJobCount(ctx context.Context) (int64, error)

GetRunningJobCount: Get number of jobs in running queue

func (*QueueManager) MoveToFailed

func (qm *QueueManager) MoveToFailed(ctx context.Context, job *common.Job, reason string) error

MoveToFailed: Move a job from running to failed queue Call this when job execution fails

func (*QueueManager) MoveToRunning

func (qm *QueueManager) MoveToRunning(ctx context.Context, job *common.Job) error

MoveToRunning: Move a job from pending to running queue Call this when job is scheduled and pod is created

func (*QueueManager) RequeueFailed

func (qm *QueueManager) RequeueFailed(ctx context.Context, job *common.Job) error

RequeueFailed: Re-queue a failed job with exponential backoff Implements: delay = min(300s, 2^attempt * 1s)

Jump to

Keyboard shortcuts

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