Skip to content

Latest commit

 

History

History
231 lines (157 loc) · 6.51 KB

File metadata and controls

231 lines (157 loc) · 6.51 KB

worker

import "github.com/its-ernest/rundown-workers/cmd/worker"

Index

CompleteRequest identifies a job to be marked as finished.

type CompleteRequest struct {
    ID string `json:"id"`
}

EnqueueRequest defines the parameters for adding a new job to a queue.

type EnqueueRequest struct {
    Queue      string `json:"queue"`
    Payload    string `json:"payload"`
    Timeout    int    `json:"timeout"`
    MaxRetries int    `json:"max_retries"`
}

FailRequest identifies a job to be marked as failed.

type FailRequest struct {
    ID string `json:"id"`
}

PollRequest defines the queue to poll for new jobs.

type PollRequest struct {
    Queue string `json:"queue"`
}

store

import "github.com/its-ernest/rundown-workers/internal/store"

Index

SQLiteStore provides a lightweight persistent storage implementation using SQLite.

It is designed to handle multiple worker processes safely using IMMEDIATE transactions for polling.

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

func NewSQLiteStore(dbPath string) (*SQLiteStore, error)

NewSQLiteStore initializes a new Store and runs all necessary schema migrations.

func (*SQLiteStore) CleanupStale

func (s *SQLiteStore) CleanupStale() (int64, error)

func (*SQLiteStore) Complete

func (s *SQLiteStore) Complete(id string) error

func (*SQLiteStore) Enqueue

func (s *SQLiteStore) Enqueue(queue, payload string, timeout, maxRetries int) (*engine.Job, error)

func (*SQLiteStore) Fail

func (s *SQLiteStore) Fail(id string) error

func (*SQLiteStore) Poll

func (s *SQLiteStore) Poll(queue string) (*engine.Job, error)

type Store

Store defines the required operations for job persistence and lifecycle management.

type Store interface {
    // Enqueue adds a new job to the specified queue.
    Enqueue(queue, payload string, timeout, maxRetries int) (*engine.Job, error)

    // Poll picks the oldest pending job that is ready to run.
    Poll(queue string) (*engine.Job, error)

    Complete(id string) error

    Fail(id string) error

    CleanupStale() (int64, error)
}

engine

import "github.com/its-ernest/rundown-workers/pkg/engine"

Index

type Job

Job is the primary unit of work in Rundown-Workers.

It contains the payload to be processed, the current status, and metadata required for retry logic and timeout enforcement.

type Job struct {
    ID         string    `json:"id"`
    Queue      string    `json:"queue"`
    Payload    string    `json:"payload"`
    Status     JobStatus `json:"status"`
    Retries    int       `json:"retries"`     // How many times this job has been attempted.
    MaxRetries int       `json:"max_retries"` // Maximum allowed retries before moving to StatusFailed.
    Timeout    int       `json:"timeout"`     // Total seconds allowed for execution before being marked stale.
    CreatedAt  time.Time `json:"created_at"`
    UpdatedAt  time.Time `json:"updated_at"`
    NextRunAt  time.Time `json:"next_run_at"` // The time when the job is eligible to be picked up again (for retries).
}

JobStatus represents the current lifecycle state of a workflow job.

type JobStatus string

const (
    // StatusPending means the job is in the queue and waiting for a worker.
    StatusPending JobStatus = "pending"

    // StatusRunning means a worker has picked up the job and is currently executing it.
    StatusRunning JobStatus = "running"

    // StatusDone means the job completed successfully.
    StatusDone JobStatus = "done"

    // StatusFailed means the job failed all retry attempts or was marked as fatal.
    StatusFailed JobStatus = "failed"
)

Generated by gomarkdoc