sync

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package sync provides flag definition synchronization from parsed descriptors into PostgreSQL. Both pbflags-sync and pbflags-admin (standalone mode) use this package to write definitions to the database.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CollectLaunches added in v0.17.0

func CollectLaunches(
	configs map[string]*configfile.Config,
	configDir string,
	hashableDims map[string]bool,
	scopeDims map[string]map[string]bool,
	featureScopes map[string][]string,
) (*launchCollection, error)

collectLaunches gathers launch definitions and references from parsed configs and the launches/ subdirectory. Returns an error if validation fails (duplicate IDs, missing references, scope violations, non-UNIFORM dimensions, dimension not present in all affected scopes).

scopeDims maps scope name → set of available dimension names. featureScopes maps featureID → list of scope names. Both may be nil to skip scope-presence validation (e.g. when descriptors are not available).

func Compile added in v0.17.0

func Compile(descriptorData []byte, configDir string) ([]byte, error)

Compile reads proto descriptors and YAML config files, compiles everything, and returns a serialized CompiledBundle protobuf.

func FlagTypeString

func FlagTypeString(ft pbflagsv1.FlagType) string

FlagTypeString converts a FlagType enum to the string stored in the DB, stripping the "FLAG_TYPE_" prefix (e.g. FLAG_TYPE_BOOL -> "BOOL").

Types

type ConditionResult added in v0.16.0

type ConditionResult struct {
	FlagsUpdated int
	Warnings     []string
}

ConditionResult reports what the condition sync did.

func SyncConditions added in v0.16.0

func SyncConditions(
	ctx context.Context,
	conn *pgx.Conn,
	configDir string,
	descriptorData []byte,
	defs []evaluator.FlagDef,
	logger *slog.Logger,
	sha string,
) (ConditionResult, error)

SyncConditions compiles YAML config files from configDir and writes conditions, dimension_metadata, and cel_version to the flags table.

type LoadResult added in v0.17.0

type LoadResult struct {
	Features          int
	FlagsUpserted     int
	FlagsArchived     int
	ConditionsUpdated int
}

LoadResult reports what the bundle load did.

func LoadBundle added in v0.17.0

func LoadBundle(ctx context.Context, conn *pgx.Conn, bundleData []byte, sha string) (LoadResult, error)

LoadBundle deserializes a CompiledBundle and writes it to the database. No proto descriptors or CEL compiler needed — all compilation was done at compile time.

Returns *LockHeldError when the global sync lock is held.

type LockHeldError added in v0.20.0

type LockHeldError struct {
	Info LockInfo
}

LockHeldError is returned by sync entry points when the global sync lock is held. The CLI maps this to a non-zero exit with a friendly message that includes the unlock command.

func IsLockHeld added in v0.20.0

func IsLockHeld(err error) (*LockHeldError, bool)

IsLockHeld unwraps an error chain looking for a LockHeldError.

func (*LockHeldError) Error added in v0.20.0

func (e *LockHeldError) Error() string

type LockInfo added in v0.20.0

type LockInfo struct {
	Actor     string
	Reason    string
	CreatedAt time.Time
}

LockInfo describes the holder of an active sync lock.

type Result

type Result struct {
	Features      int
	FlagsUpserted int
	FlagsArchived int
}

Result reports what the sync did.

func SyncDefinitions

func SyncDefinitions(ctx context.Context, conn *pgx.Conn, defs []evaluator.FlagDef, logger *slog.Logger) (Result, error)

SyncDefinitions writes the given flag definitions to the database in a single transaction. It upserts features and flags, and archives flags that are no longer present in the descriptor. Runtime state (state, value) is never modified.

Returns *LockHeldError when the global sync lock is held; callers should map this to a non-zero exit with a friendly unlock hint.

Jump to

Keyboard shortcuts

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