38 lines
898 B
Go
38 lines
898 B
Go
package jobs
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
)
|
|
|
|
// JobType represents the type of job
|
|
type JobType string
|
|
|
|
const (
|
|
JobTypeArchiveLink JobType = "archive_link"
|
|
JobTypeExtractContent JobType = "extract_content"
|
|
)
|
|
|
|
// Job represents a background job
|
|
type Job struct {
|
|
ID string
|
|
Type JobType
|
|
Payload string // JSON encoded payload
|
|
Status string // pending, processing, completed, failed
|
|
CreatedAt time.Time
|
|
}
|
|
|
|
// Queue defines the interface for job queue operations
|
|
type Queue interface {
|
|
// Enqueue adds a new job to the queue
|
|
Enqueue(ctx context.Context, jobType JobType, payload any) error
|
|
|
|
// Dequeue retrieves the next job from the queue
|
|
Dequeue(ctx context.Context) (*Job, error)
|
|
|
|
// Complete marks a job as completed
|
|
Complete(ctx context.Context, jobID string) error
|
|
|
|
// Fail marks a job as failed
|
|
Fail(ctx context.Context, jobID string, errorMsg string) error
|
|
}
|