worker

package
v0.83.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package worker maintains one tenant's keyword documents: it drains the dirty queue and runs a bounded cursor backfill, building every document from ContentKit's own records through its Sources (the catalog's content, the groups').

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SyncOnce

func SyncOnce(ctx context.Context, opts Options) error

SyncOnce runs one tick: drain one dirty batch, then a bounded backfill step. No connection or transaction is held across source calls: each write is a short transaction fenced by the dirty-queue revision, so overlapping ticks are safe (only duplicated work) and a stale build never overwrites a newer one.

Types

type Options

type Options struct {
	// Pool is released before every source call, so one connection
	// suffices. Required.
	Pool   *pgxpool.Pool
	Schema string
	Tenant string

	// SupportedLanguages are the document languages backfill enumerates. Required.
	SupportedLanguages []string
	// Sources build the documents, each of its kinds; a dirty row of a kind
	// no source documents deletes its document. Required.
	Sources []Source

	// Batch sizing (defaults are conservative).
	DirtyBatchSize   int
	BackfillPageSize int
	// Upper bound on how much cursor backfill work to do per SyncOnce.
	BackfillMaxPages int
}

Options configures one tenant's worker.

type Source

type Source interface {
	// DocumentKinds are the content kinds it documents.
	DocumentKinds() []string
	// ListDocuments enumerates documented references of one kind and
	// language for backfill: one bounded page from an opaque cursor, done
	// when exhausted.
	ListDocuments(ctx context.Context, kind, language, cursor string, limit int) (refs []contentref.ContentRef, nextCursor string, done bool, err error)
	// BuildDocuments returns the current document of every reference that
	// has one in language; a missing one deletes its document. The worker
	// records invalid documents individually; an error is only for a failed
	// or incomplete read, never a partial result.
	BuildDocuments(ctx context.Context, kind, language string, refs []contentref.ContentRef) ([]search.KeywordDocument, error)
}

Source builds one family of the tenant's documents.

Jump to

Keyboard shortcuts

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