process

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: Apache-2.0 Imports: 9 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package process orchestrates the read → parse → batch → insert pipeline: split file names into DB-aware batches, run each batch in its own goroutine bounded by a worker pool (not one goroutine per file — see xpro's AGENTS.md notes on why unbounded fan-out doesn't scale safely), and retry a batch once inline when the whole transaction fails with a transient, connection-level error. This inline retry replaces the separate retry-processor daemon xpro used.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Inserter

type Inserter interface {
	InsertBatch(ctx context.Context, records []model.Record) (db.BatchResult, error)
	DefaultBatchSize() int
}

Inserter is the subset of db.Inserter that Pipeline actually uses — a small, consumer-defined interface.

type Pipeline

type Pipeline struct {
	Source     fs.FS
	Mapping    []parser.Mapping
	Target     Inserter
	BatchSize  int           // 0 = Target.DefaultBatchSize()
	Workers    int           // 0 = 8
	Limit      int           // 0 = no limit; otherwise cap the number of files processed this run
	MaxErrors  int           // 0 = 100; cap on Result.Errors entries kept
	RetryDelay time.Duration // pause before the single transient-failure retry; 0 = none
	Logger     *slog.Logger  // nil = slog.Default()
}

Pipeline wires one source through the mapping-driven parser into one target for a single run. Source is only read: whoever created it (and connected it, if it needs a session) owns closing it.

func (*Pipeline) Run

func (p *Pipeline) Run(ctx context.Context) (Result, error)

Run lists every file the Source has, splits it into batches, and drains them through a bounded worker pool. If ctx is cancelled mid-run, batches not yet started are counted as failed, in-flight batches finish or abort with their database calls, and Run returns the partial Result together with an error wrapping ctx.Err() (unless everything had already succeeded).

type Result

type Result struct {
	Files    int `json:"files"`
	Inserted int `json:"inserted"`
	// Failed counts files that were not inserted: unreadable, unparseable,
	// rejected by the database, or never started because the run was cancelled.
	Failed  int      `json:"failed"`
	Batches int      `json:"batches"`
	Errors  []string `json:"errors,omitempty"`
	// ErrorsOmitted counts failures beyond the MaxErrors kept in Errors.
	ErrorsOmitted int           `json:"errorsOmitted,omitempty"`
	Elapsed       time.Duration `json:"elapsedNs"`
}

Result summarizes one pipeline run. Every file is accounted for: Inserted + Failed == Files unless the run was interrupted (see Run).

Jump to

Keyboard shortcuts

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