queue

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package queue provides persistent operation queuing for disconnected scenarios. Operations are queued to disk and executed when connectivity is restored.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Operation

type Operation struct {
	ID        string                 `json:"id"`
	Type      string                 `json:"type"`
	AgentID   string                 `json:"agent_id"`
	Payload   map[string]interface{} `json:"payload"`
	CreatedAt time.Time              `json:"created_at"`
	Attempts  int                    `json:"attempts"`
	MaxRetry  int                    `json:"max_retry"`
	State     OperationState         `json:"state"`
	Result    *OperationResult       `json:"result,omitempty"`
	Error     string                 `json:"error,omitempty"`
}

Operation represents a queued operation to be executed when connected

type OperationResult

type OperationResult struct {
	Success  bool                   `json:"success"`
	Data     map[string]interface{} `json:"data,omitempty"`
	Duration time.Duration          `json:"duration"`
}

OperationResult holds the result of an executed operation

type OperationState

type OperationState string

OperationState represents the state of a queued operation

const (
	StatePending   OperationState = "pending"
	StateExecuting OperationState = "executing"
	StateCompleted OperationState = "completed"
	StateFailed    OperationState = "failed"
	StateCancelled OperationState = "cancelled"
)

type Queue

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

Queue manages persistent operation queuing

func New

func New(queueDir string) (*Queue, error)

New creates a new operation queue

func (*Queue) Cancel

func (q *Queue) Cancel(opID string) error

Cancel marks an operation as cancelled

func (*Queue) Clear

func (q *Queue) Clear() error

Clear removes all completed/failed/cancelled operations

func (*Queue) Close

func (q *Queue) Close() error

Close cleans up the queue (no-op for disk-based queue)

func (*Queue) Complete

func (q *Queue) Complete(opID string, result *OperationResult) error

Complete marks an operation as completed

func (*Queue) Dequeue

func (q *Queue) Dequeue() *Operation

Dequeue returns the next pending operation

func (*Queue) Enqueue

func (q *Queue) Enqueue(op *Operation) error

Enqueue adds an operation to the queue

func (*Queue) Fail

func (q *Queue) Fail(opID string, err error) error

Fail marks an operation as failed, with retry logic

func (*Queue) Get

func (q *Queue) Get(opID string) (*Operation, error)

Get returns a specific operation by ID

func (*Queue) IsExecuting

func (q *Queue) IsExecuting(opID string) bool

IsExecuting returns true if an operation is currently executing

func (*Queue) List

func (q *Queue) List(filter *OperationState) []*Operation

List returns all operations, optionally filtered by state

func (*Queue) MarkExecuting

func (q *Queue) MarkExecuting(opID string)

MarkExecuting marks an operation as executing

func (*Queue) PendingCount

func (q *Queue) PendingCount() int

PendingCount returns the number of pending operations

Jump to

Keyboard shortcuts

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