queue

package
v0.0.23 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Actions = "Action"

	DirectQueue = "DirectQueue"
	MainQueue   = "MainQueue"
	BackupQueue = "BackupQueue"

	// MaxDeliveryAttempts caps how many times an action is offered to the node before it
	// is given up, so an action the node can never accept cannot block its queue forever.
	MaxDeliveryAttempts = 5
)

Variables

View Source
var (
	// ErrInvalidQueueID is returned when an unrecognized queue ID is provided.
	ErrInvalidQueueID = errors.New("invalid queue id")

	// ErrDeliveryExhausted is returned by Delivery.Restore once MaxDeliveryAttempts is spent.
	ErrDeliveryExhausted = errors.New("delivery attempts exhausted")
)

Functions

func DirectInstructionToAction

func DirectInstructionToAction(i *types.DirectInstruction) (*types.Action, error)

DirectInstructionToAction converts a DirectInstruction into an Action with a randomly generated ID.

func PrepareDirectAction

func PrepareDirectAction(opType op.Type, opCommand op.Command, msg []byte) (*types.Action, error)

PrepareDirectAction wraps a payload as a Direct/Submit action ready for enqueue.

Types

type ActionQueues

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

ActionQueues manages direct, main, and backup Redis-backed queues for action submission.

func NewActionQueues

func NewActionQueues(client *redis.Client, actionTTL time.Duration, m *metrics.Metrics) *ActionQueues

NewActionQueues creates a new ActionQueues backed by the given Redis client. m may be nil or disabled.

func (*ActionQueues) Dequeue

func (as *ActionQueues) Dequeue(ctx context.Context, queueID processorutils.QueueID) (*Delivery, error)

Dequeue takes the next action off the indicated queue and returns it as a Delivery the caller must Commit or Restore. If no action is available, wrapped ErrEmptyQueue is returned.

ctx cancellation is honoured only before the queue ID is consumed: an interrupted body fetch would leave the action neither queued nor delivered.

func (*ActionQueues) Enqueue

func (as *ActionQueues) Enqueue(ctx context.Context, action *types.Action, queueID processorutils.QueueID) error

Enqueue stores the action and appends its submission ID to the indicated queue.

func (*ActionQueues) QueueLength

func (as *ActionQueues) QueueLength(ctx context.Context) (int64, error)

QueueLength returns the number of elements in the main queue.

type ActionSubmissionID

type ActionSubmissionID struct {
	ActionID      common.Hash
	SubmissionTag types.SubmissionTag
	// Attempt counts the deliveries already attempted; absent on entries queued before
	// redelivery existed, and never part of the action's storage key.
	Attempt uint8 `json:"attempt,omitempty"`
}

ActionSubmissionID uniquely identifies an action by its action ID and submission tag.

func (*ActionSubmissionID) String

func (id *ActionSubmissionID) String() string

String returns a combined string representation of the action ID and submission tag.

type Delivery added in v0.0.23

type Delivery struct {
	// Action is the dequeued action.
	Action *types.Action
	// contains filtered or unexported fields
}

Delivery is an action taken off its queue whose body is still stored. Exactly one of Commit or Restore must be called once the send outcome is known; calling neither leaves the action off its queue until the body expires.

func (*Delivery) Commit added in v0.0.23

func (d *Delivery) Commit() error

Commit drops the action body once the node has received the action.

func (*Delivery) Restore added in v0.0.23

func (d *Delivery) Restore() error

Restore returns an action the node did not receive to the dequeue end of its queue, so the next poll retries it. A non-nil error means the action was given up instead: its attempts are spent or the queue write failed, and the action is lost.

Jump to

Keyboard shortcuts

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