crawl

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package crawl executes bounded batches from the durable crawl frontier.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Decision

type Decision struct {
	Terminal    bool
	FailureKind string
	RetryAt     time.Time
}

Decision describes how a failed item returns to the frontier.

type Frontier

type Frontier interface {
	LeaseFrontierItems(ctx context.Context, worker string, now time.Time, leaseDuration time.Duration, limit, budget int) ([]corpus.FrontierItem, error)
	ReleaseFrontierItem(ctx context.Context, id int64, worker string, now time.Time) error
	CompleteFrontierItem(ctx context.Context, id int64, worker string, now time.Time) error
	RetryFrontierItem(ctx context.Context, id int64, worker, message string, earliestRunAt, now time.Time) error
	FailFrontierItem(ctx context.Context, id int64, worker, failureKind, message string, now time.Time) error
}

Frontier is the durable lease boundary required by a Worker.

type Handler

type Handler interface {
	Handle(context.Context, corpus.FrontierItem) error
}

Handler hydrates one leased frontier item. It must respect ctx and return only after all writes for the item are durable.

type HandlerFunc

type HandlerFunc func(context.Context, corpus.FrontierItem) error

HandlerFunc adapts a function to Handler.

func (HandlerFunc) Handle

func (f HandlerFunc) Handle(ctx context.Context, item corpus.FrontierItem) error

type Stats

type Stats struct {
	Leased    int
	Completed int
	Retried   int
	Failed    int
	Budget    int
}

Stats reports actual work performed by one bounded batch.

type TerminalError

type TerminalError struct {
	Kind string
	Err  error
}

TerminalError tells the worker that retrying an item cannot succeed without a source-state change.

func (*TerminalError) Error

func (e *TerminalError) Error() string

func (*TerminalError) Unwrap

func (e *TerminalError) Unwrap() error

type Worker

type Worker struct {
	Frontier       Frontier
	Handler        Handler
	ID             string
	BatchSize      int
	Budget         int
	LeaseDuration  time.Duration
	HandlerTimeout time.Duration
	Backoff        time.Duration
	Now            func() time.Time
	Classify       func(error, corpus.FrontierItem, time.Time) Decision
}

Worker leases and executes one bounded batch at a time.

func (*Worker) RunOnce

func (w *Worker) RunOnce(ctx context.Context) (Stats, error)

RunOnce executes at most one configured batch. It is intentionally synchronous: callers control scheduling and can run independent workers when they need concurrency.

Jump to

Keyboard shortcuts

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