offset

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultOffsetFile = ".mailgrid.offset"

Variables

This section is empty.

Functions

This section is empty.

Types

type OffsetInfo

type OffsetInfo struct {
	JobID  string `json:"job_id"`
	Offset int    `json:"offset"`
	Total  int    `json:"total,omitempty"`
}

OffsetInfo contains information about the current offset state

type Tracker

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

Tracker manages email delivery offset tracking for resumable campaigns.

Concurrency model:

  • GetOffset / ShouldSkip / GetJobID / GetInfo: read-only; safe from any goroutine.
  • UpdateOffset / SetJobID: writer methods used by the CLI before/after dispatch.
  • MarkComplete: hot-path call from worker goroutines. Maintains a contiguous high-water mark so the persisted offset advances only past indices that have all been completed (correct under concurrent out-of-order completion).
  • Save: serializes to disk; the file write happens outside the lock so readers and MarkComplete callers do not block on I/O.

func NewTracker

func NewTracker(filePath string) *Tracker

NewTracker creates a new offset tracker

func (*Tracker) GetInfo

func (t *Tracker) GetInfo() OffsetInfo

GetInfo returns current offset information

func (*Tracker) GetJobID

func (t *Tracker) GetJobID() string

GetJobID returns the current job ID

func (*Tracker) GetOffset

func (t *Tracker) GetOffset() int

GetOffset returns the current offset (contiguous high-water mark).

func (*Tracker) Load

func (t *Tracker) Load() error

Load reads the offset from the file

func (*Tracker) MarkComplete

func (t *Tracker) MarkComplete(idx int)

MarkComplete records that the absolute task index `idx` has been delivered. The persisted offset advances to one past the highest index N such that all indices in [t.offset, N] have been marked complete. Indices that arrive out of order are buffered in t.pending and drained when the gap closes.

Indices that arrive below the current offset (e.g. duplicates from a retry after a flusher has already moved past) are ignored.

func (*Tracker) Reset

func (t *Tracker) Reset() error

Reset clears the offset and removes the offset file

func (*Tracker) Save

func (t *Tracker) Save() error

Save writes the current offset to disk atomically (write to temp + rename). The disk I/O happens outside the tracker lock so concurrent MarkComplete callers are not blocked on fsync.

func (*Tracker) SetJobID

func (t *Tracker) SetJobID(jobID string)

SetJobID sets the job ID for this campaign

func (*Tracker) ShouldSkip

func (t *Tracker) ShouldSkip(index int) bool

ShouldSkip returns true if the given index should be skipped based on offset

func (*Tracker) UpdateOffset

func (t *Tracker) UpdateOffset(newOffset int)

UpdateOffset sets the offset directly. Used by the CLI to seed the tracker from a persisted state and by tests; production worker code should use MarkComplete instead. Calling UpdateOffset clears any pending out-of-order completions because they no longer correspond to a meaningful baseline.

Jump to

Keyboard shortcuts

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