sync

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2026 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RunOnceScopeNameFull      = "runonce_full"
	RunOnceScopeNameDiscovery = "runonce_discovery"
)
View Source
const (
	LockModeLease    = "lease"
	LockModeAdvisory = "advisory"
)

Variables

View Source
var ErrNoConnectorsDue = errors.New("no connectors are due to sync")

ErrNoConnectorsDue is returned when all enabled connectors are deferred by a run policy (interval/backoff) and there is no work to do.

View Source
var ErrNoEnabledConnectors = errors.New("no enabled connectors are configured")
View Source
var ErrSyncAlreadyRunning = errors.New("sync is already running")

ErrSyncAlreadyRunning is returned by a try-lock runner when another sync pass is already in progress.

View Source
var ErrSyncQueued = errors.New("sync queued")

ErrSyncQueued is returned when a sync request is accepted but will be processed asynchronously by the worker.

Functions

func ConnectorScopeFromContext added in v0.4.3

func ConnectorScopeFromContext(ctx context.Context) (connectorKind, sourceName string, ok bool)

func IsForcedSync added in v0.2.0

func IsForcedSync(ctx context.Context) bool

func ListenForSyncJobSignals added in v0.4.8

func ListenForSyncJobSignals(ctx context.Context, pool *pgxpool.Pool, channel string, out chan<- struct{}) error

func NewSyncJobStore added in v0.4.8

func NewSyncJobStore(db gen.DBTX) syncJobStore

func SyncJobConsumerScopeNameForMode added in v0.4.8

func SyncJobConsumerScopeNameForMode(mode registry.RunMode) string

func SyncJobLaneForMode added in v0.4.8

func SyncJobLaneForMode(mode registry.RunMode) string

func SyncJobNotifyChannelForMode added in v0.4.8

func SyncJobNotifyChannelForMode(mode registry.RunMode) string

func WithConnectorScope added in v0.4.3

func WithConnectorScope(ctx context.Context, connectorKind, sourceName string) context.Context

func WithForcedSync added in v0.2.0

func WithForcedSync(ctx context.Context) context.Context

Types

type DBRunner

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

func NewDBRunner

func NewDBRunner(pool *pgxpool.Pool, reg *registry.ConnectorRegistry) *DBRunner

func (*DBRunner) EnableDiscoveryMetricsRefresh added in v0.4.11

func (r *DBRunner) EnableDiscoveryMetricsRefresh()

func (*DBRunner) PlannedConnectorScopes added in v0.4.8

func (r *DBRunner) PlannedConnectorScopes(ctx context.Context) ([]TriggerRequest, error)

func (*DBRunner) Prepare added in v0.4.8

func (r *DBRunner) Prepare(ctx context.Context) error

func (*DBRunner) RunOnce

func (r *DBRunner) RunOnce(ctx context.Context) error

func (*DBRunner) SetGlobalEvalMode added in v0.2.0

func (r *DBRunner) SetGlobalEvalMode(mode string)

func (*DBRunner) SetLockManager added in v0.2.2

func (r *DBRunner) SetLockManager(m LockManager)

func (*DBRunner) SetReadModelConfig added in v0.4.11

func (r *DBRunner) SetReadModelConfig(cfg readmodels.RefreshConfig)

func (*DBRunner) SetReporter

func (r *DBRunner) SetReporter(reporter registry.Reporter)

func (*DBRunner) SetRunMode added in v0.4.0

func (r *DBRunner) SetRunMode(mode registry.RunMode)

func (*DBRunner) SetRunPolicy added in v0.2.0

func (r *DBRunner) SetRunPolicy(policy RunPolicy)

type Lock added in v0.2.2

type Lock interface {
	ScopeKind() string
	ScopeName() string
	StartHeartbeat(ctx context.Context, onLost func(error)) (stop func())
	Release(ctx context.Context) error
}

type LockManager added in v0.2.2

type LockManager interface {
	TryAcquire(ctx context.Context, scopeKind, scopeName string) (Lock, bool, error)
	Acquire(ctx context.Context, scopeKind, scopeName string) (Lock, error)
}

func NewLockManager added in v0.2.2

func NewLockManager(pool *pgxpool.Pool, cfg LockManagerConfig) (LockManager, error)

type LockManagerConfig added in v0.2.2

type LockManagerConfig struct {
	Mode              string
	InstanceID        string
	TTL               time.Duration
	HeartbeatInterval time.Duration
	HeartbeatTimeout  time.Duration
}

type LogReporter

type LogReporter struct {
	Logger              *slog.Logger
	ProgressInterval    time.Duration
	ProgressPercentStep int64
	// contains filtered or unexported fields
}

LogReporter is a simple reporter that logs events to the default slog logger.

func (*LogReporter) Report

func (r *LogReporter) Report(e registry.Event)

type Orchestrator

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

func NewOrchestrator

func NewOrchestrator(pool *pgxpool.Pool, reg *registry.ConnectorRegistry) *Orchestrator

func (*Orchestrator) AddIntegration

func (o *Orchestrator) AddIntegration(i registry.Integration) error

func (*Orchestrator) RunOnce

func (o *Orchestrator) RunOnce(ctx context.Context) error

func (*Orchestrator) SetGlobalEvalMode added in v0.2.0

func (o *Orchestrator) SetGlobalEvalMode(mode string)

func (*Orchestrator) SetLockManager added in v0.2.2

func (o *Orchestrator) SetLockManager(m LockManager)

func (*Orchestrator) SetReadModelConfig added in v0.4.11

func (o *Orchestrator) SetReadModelConfig(cfg readmodels.RefreshConfig)

func (*Orchestrator) SetReporter

func (o *Orchestrator) SetReporter(r registry.Reporter)

func (*Orchestrator) SetRunMode added in v0.4.0

func (o *Orchestrator) SetRunMode(mode registry.RunMode)

type ResyncQueueRunner added in v0.4.8

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

func (*ResyncQueueRunner) RunOnce added in v0.4.8

func (r *ResyncQueueRunner) RunOnce(ctx context.Context) error

type RunPolicy added in v0.2.0

type RunPolicy struct {
	IntervalByKind       map[string]time.Duration
	FailureBackoffBase   time.Duration
	FailureBackoffMax    time.Duration
	RecentFinishedRunCap int
	Now                  func() time.Time
}

type Runner

type Runner interface {
	RunOnce(context.Context) error
}

Runner executes a single sync pass.

func NewBlockingRunOnceLockRunnerWithScope added in v0.4.0

func NewBlockingRunOnceLockRunnerWithScope(locks LockManager, inner Runner, scopeName string) Runner

func NewCompositeRunner added in v0.4.0

func NewCompositeRunner(runners ...Runner) Runner

func NewResyncQueueRunnerWithPlanner added in v0.4.8

func NewResyncQueueRunnerWithPlanner(dbStore syncJobStore, planner manualSyncPlanner, mode registry.RunMode) Runner

func NewTryRunOnceLockRunnerWithScope added in v0.4.0

func NewTryRunOnceLockRunnerWithScope(locks LockManager, inner Runner, scopeName string) Runner

type Scheduler

type Scheduler struct {
	Runner   Runner
	Interval time.Duration
	Trigger  <-chan TriggerRequest
}

func (*Scheduler) Run

func (s *Scheduler) Run(ctx context.Context)

type SyncJobConsumer added in v0.4.8

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

func NewSyncJobConsumer added in v0.4.8

func NewSyncJobConsumer(store syncJobStore, locks LockManager, runner Runner, cfg SyncJobConsumerConfig) *SyncJobConsumer

func (*SyncJobConsumer) Run added in v0.4.8

func (c *SyncJobConsumer) Run(ctx context.Context) error

type SyncJobConsumerConfig added in v0.4.8

type SyncJobConsumerConfig struct {
	Mode              registry.RunMode
	PollInterval      time.Duration
	LeaseTTL          time.Duration
	HeartbeatInterval time.Duration
	RetryBaseDelay    time.Duration
	RetryMaxDelay     time.Duration
	ClaimedBy         string
	Wakeups           <-chan struct{}
}

type TriggerRequest added in v0.4.3

type TriggerRequest struct {
	ConnectorKind string `json:"connector_kind,omitempty"`
	SourceName    string `json:"source_name,omitempty"`
}

func (TriggerRequest) HasConnectorScope added in v0.4.3

func (r TriggerRequest) HasConnectorScope() bool

func (TriggerRequest) Normalized added in v0.4.3

func (r TriggerRequest) Normalized() TriggerRequest

Jump to

Keyboard shortcuts

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