package jobs

import "github.com/go-arrower/arrower/contexts/admin/internal/domain/jobs"

Index

Constants

const DefaultQueueName = QueueName("Default")

Variables

var ErrJobLockedAlready = fmt.Errorf("%w: job might be processing already", postgres.ErrQueryFailed)

Types

type Filter

type Filter struct {
	Queue   QueueName
	JobType JobType
}

type FinishedJob

type FinishedJob struct {
	ID         string
	CreatedAt  time.Time
	UpdatedAt  time.Time
	RunAt      time.Time
	Type       JobType
	Queue      QueueName
	Payload    string
	Priority   int16
	RunCount   int32
	RunError   string
	Success    bool
	FinishedAt time.Time
	// contains filtered or unexported fields
}

type Job

type Job struct {
	ID         string
	CreatedAt  time.Time
	UpdatedAt  time.Time
	RunAt      time.Time
	Type       JobType
	Queue      QueueName
	Payload    string
	LastError  string
	ErrorCount int32
	Priority   int16
}

Job could also have "runs" how many times it was executed with error etc.

type JobType

type JobType string

type QueueKPIs

type QueueKPIs struct {
	PendingJobsPerType map[string]int
	PendingJobs        int
	FailedJobs         int
	ProcessedJobs      int
	AvailableWorkers   int
	AverageTimePerJob  time.Duration
}

type QueueName

type QueueName string

type QueueNames

type QueueNames []QueueName

type QueueStats

type QueueStats struct {
	QueueName            QueueName
	PendingJobs          int
	PendingJobsPerType   map[string]int
	FailedJobs           int
	ProcessedJobs        int
	AvailableWorkers     int
	PendingJobsErrorRate float64 // can be calculated: FailedJobs * 100 / PendingJobs
	AverageTimePerJob    time.Duration
	EstimateUntilEmpty   time.Duration // can be calculated
}

type Repository

type Repository interface {
	FindAllQueueNames(ctx context.Context) (QueueNames, error)
	PendingJobs(ctx context.Context, queue QueueName) ([]Job, error)
	QueueKPIs(ctx context.Context, queue QueueName) (QueueKPIs, error)
	DeleteByID(ctx context.Context, jobID string) error
	RunJobAt(ctx context.Context, jobID string, runAt time.Time) error
	WorkerPools(ctx context.Context) ([]WorkerPool, error)
	Schedules(ctx context.Context) ([]Schedule, error)
	FinishedJobs(ctx context.Context, f Filter) ([]Job, error)
	FinishedJobsTotal(ctx context.Context, f Filter) (int64, error)
}

Repository manages the data access to the underlying jobs' implementation.

type Schedule

type Schedule struct {
	Queue   QueueName
	Spec    string
	JobType JobType
	Args    any
}

type WorkerPool

type WorkerPool struct {
	InstanceName string
	Version      string
	Queue        QueueName
	LastSeenAt   time.Time
	JobTypes     []JobType
	Workers      int
}

Source Files

jobs.business.go jobs.repository.go

Version
v0.0.0-20250311203644-ab26c1152cb4 (latest)
Published
Mar 11, 2025
Platform
linux/amd64
Imports
4 packages
Last checked
9 minutes ago

Tools for package owners.