sp2-verify-1770324794/pkg/redisqueue/job.go
rdev-worker 154c535204
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
build: /implement-feature async-jobs --requirements 'API: POST /jobs pushes ...
2026-02-05 21:04:47 +00:00

44 lines
1.2 KiB
Go

// Package redisqueue provides a Redis-backed job queue for async processing.
package redisqueue
import (
"errors"
"time"
)
// Job represents an async job in the queue.
type Job struct {
ID string `json:"id"`
Type string `json:"type"`
Payload map[string]any `json:"payload"`
Status JobStatus `json:"status"`
CreatedAt time.Time `json:"created_at"`
StartedAt *time.Time `json:"started_at,omitempty"`
CompletedAt *time.Time `json:"completed_at,omitempty"`
Error string `json:"error,omitempty"`
}
// JobStatus represents the current state of a job.
type JobStatus string
const (
StatusPending JobStatus = "pending"
StatusRunning JobStatus = "running"
StatusCompleted JobStatus = "completed"
StatusFailed JobStatus = "failed"
)
// String returns the string representation of the status.
func (s JobStatus) String() string {
return string(s)
}
// Sentinel errors.
var (
// ErrNoJob is returned when the queue has no pending jobs.
ErrNoJob = errors.New("no job available")
// ErrJobNotFound is returned when a job ID doesn't exist.
ErrJobNotFound = errors.New("job not found")
)