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 ¶
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).