bulk

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package bulk is the chunked bulk-operation framework (roadmap E6): start a set of items, process them in caller-sized chunks with per-item isolation, record a partial-failure ledger, and resume after an interruption.

Each item is processed in its own transaction, and its success status commits ATOMICALLY with the item's work — so a crash re-processes only the items not yet marked done (resumable), and one item's failure neither rolls back the others nor stops the run (partial-failure ledger). Item work must be idempotent, like a job worker (a re-run after a crash may repeat the last in-flight item).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ItemFunc

type ItemFunc func(ctx context.Context, db database.TenantDB, payload []byte) error

ItemFunc processes one item's payload inside the item's own tenant transaction. Returning an error records the item as failed (with the error) and rolls back any work it did; returning nil commits the work together with the done mark.

type Progress

type Progress struct {
	Total   int
	Done    int
	Failed  int
	Pending int
	Status  string // pending | running | completed
}

Progress is a bulk operation's live counts.

type Service

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

Service starts and drives bulk operations.

func New

func New(idgen model.IDGen) *Service

New builds the service. idgen mints operation and item ids.

func (*Service) Process

func (s *Service) Process(ctx context.Context, txm database.TxManager, tenantID, bulkID uuid.UUID, limit int, fn ItemFunc) (int, error)

Process runs up to `limit` pending items of the operation (limit <= 0 = all remaining), each in its own tenant transaction, and returns how many it processed this call. Re-run to continue — Process is resumable and picks up only still-pending items. When no pending items remain it marks the operation completed. txm is the tenant runtime TxManager (app_rt); a worker drives this per operation, binding tenantID for each item's transaction.

func (*Service) Progress

func (s *Service) Progress(ctx context.Context, db database.TenantDB, bulkID uuid.UUID) (Progress, error)

Progress reports live counts for an operation, in the caller's tenant tx.

func (*Service) Start

func (s *Service) Start(ctx context.Context, db database.TenantDB, kind string, items []json.RawMessage) (uuid.UUID, error)

Start creates a bulk operation of kind with one pending item per payload, in the caller's tenant transaction (so the operation and its items commit with any business write that spawned them). Returns the operation id. An empty item set is allowed (a completed no-op operation).

Jump to

Keyboard shortcuts

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