mailbox

package
v0.3.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: May 16, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package mailbox provides file-based task queue implementation

Package mailbox provides file-based task queue implementation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTaskExists   = fmt.Errorf("task already exists in inbox")
	ErrNoTasks      = fmt.Errorf("no tasks available")
	ErrMailboxDir   = fmt.Errorf("mailbox directory error")
	ErrTaskNotFound = fmt.Errorf("task not found")
	ErrInvalidTask  = fmt.Errorf("invalid task format")
)

Errors

Functions

This section is empty.

Types

type Config

type Config struct {
	// Directory is the base path for the mailbox
	Directory string

	// Retention periods for cleanup
	OutboxRetention time.Duration
	FailedRetention time.Duration
	TmpCleanupAge   time.Duration

	// Scan interval for orphaned task recovery
	OrphanScanInterval time.Duration
}

Config holds mailbox configuration

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns default mailbox configuration

type FileMailbox

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

FileMailbox implements a file-based task queue

func NewFileMailbox

func NewFileMailbox(cfg *Config) (*FileMailbox, error)

NewFileMailbox creates a new file-based mailbox

func (*FileMailbox) Claim

func (m *FileMailbox) Claim(workerID string) (*types.Task, error)

Claim attempts to claim a task from inbox Returns nil task and nil error if no tasks available (ErrNoTasks)

func (*FileMailbox) Complete

func (m *FileMailbox) Complete(taskID string, result *TaskResult) error

Complete moves a task from processing to outbox

func (*FileMailbox) Enqueue

func (m *FileMailbox) Enqueue(task *types.Task) error

Enqueue writes a task to the inbox

func (*FileMailbox) Fail

func (m *FileMailbox) Fail(taskID string, taskErr *TaskError) error

Fail moves a task from processing to failed

func (*FileMailbox) Start

func (m *FileMailbox) Start()

Start begins background cleanup routines

func (*FileMailbox) Stop

func (m *FileMailbox) Stop()

Stop gracefully shuts down the mailbox

type TaskError

type TaskError struct {
	TaskID        string `json:"task_id"`
	Error         string `json:"error"`
	Attempts      int    `json:"attempts"`
	LastAttemptAt int64  `json:"last_attempt_at"`
	FailedAt      int64  `json:"failed_at"`
}

TaskError represents information about a failed task

type TaskResult

type TaskResult struct {
	TaskID        string            `json:"task_id"`
	Status        types.TaskStatus  `json:"status"`
	Verdict       types.TaskVerdict `json:"verdict"`
	VerdictReason string            `json:"verdict_reason"`
	Output        string            `json:"output"`
	DurationMs    int64             `json:"duration_ms"`
	CompletedAt   int64             `json:"completed_at"`
}

TaskResult represents the result of a completed task

Jump to

Keyboard shortcuts

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