Documentation
¶
Overview ¶
Package catalogscheduler composes deployment-owned synchronization policy above Starmap's explicit idempotent Sync operation.
Index ¶
- Constants
- type AlertSeverity
- type AttemptRecord
- type AttemptStatus
- type BaselineReadiness
- type BaselineReadinessProbe
- type CatalogIdentity
- type CurrentGenerationReader
- type FilesystemLease
- type FreshnessAlert
- type FreshnessMonitor
- func (m *FreshnessMonitor) Record(observations []catalogs.SourceObservationLink) error
- func (m *FreshnessMonitor) RecordManifest(manifest catalogs.GenerationManifest) error
- func (m *FreshnessMonitor) RecordResult(result *pkgsync.Result) error
- func (m *FreshnessMonitor) RecordRuns(records []RunRecord) error
- func (m *FreshnessMonitor) Report(at time.Time) (FreshnessReport, error)
- type FreshnessPolicy
- type FreshnessReport
- type FreshnessState
- type InitialRunController
- func (c *InitialRunController) Readiness() InitialRunReadiness
- func (c *InitialRunController) RunScheduledAt(ctx context.Context, dueAt time.Time, jitterWindow time.Duration, ...) (RunResult, error)
- func (c *InitialRunController) Start(ctx context.Context, options ...pkgsync.Option) error
- func (c *InitialRunController) Wait(ctx context.Context) (RunResult, error)
- type InitialRunMode
- type InitialRunPolicy
- type InitialRunReadiness
- type InitialRunState
- type Lease
- type LeaseGuard
- type LeaseRequest
- type MemoryLease
- type MemoryRunLedger
- func (l *MemoryRunLedger) Begin(ctx context.Context, record RunRecord) error
- func (l *MemoryRunLedger) Complete(ctx context.Context, record RunRecord) error
- func (l *MemoryRunLedger) Get(ctx context.Context, runID string) (RunRecord, error)
- func (l *MemoryRunLedger) List(ctx context.Context, query RunQuery) ([]RunRecord, error)
- func (l *MemoryRunLedger) RecordAttempt(ctx context.Context, runID string, attempt AttemptRecord) error
- type OperationalRun
- type OperationalState
- type Operations
- type OperationsOption
- type RetryClass
- type RetryPolicy
- type RunLedger
- type RunQuery
- type RunRecord
- type RunResult
- type RunStatus
- type Runner
- type RunnerOption
- type SQLRunLedger
- func (l *SQLRunLedger) Begin(ctx context.Context, record RunRecord) error
- func (l *SQLRunLedger) Complete(ctx context.Context, record RunRecord) error
- func (l *SQLRunLedger) Get(ctx context.Context, runID string) (RunRecord, error)
- func (l *SQLRunLedger) List(ctx context.Context, query RunQuery) ([]RunRecord, error)
- func (l *SQLRunLedger) RecordAttempt(ctx context.Context, runID string, attempt AttemptRecord) error
- type SchedulerOperationalState
- type SourceFreshness
- type SourceFreshnessSLA
- type Syncer
- type Trigger
Constants ¶
const ( FreshnessAlertSourceMissing = "source_freshness_missing" FreshnessAlertSourceFuture = "source_freshness_future" FreshnessAlertSourceStale = "source_freshness_stale" FreshnessAlertSourceDegraded = "source_observation_degraded" )
Stable freshness alert codes.
const ( InitialRunIssuePending = "initial_run_pending" InitialRunIssueFailed = "initial_run_failed" InitialRunIssueLeaseHeld = "initial_run_lease_held" InitialRunIssueBaseline = "initial_run_baseline_unready" )
Stable startup-readiness issue codes.
const ( // DefaultLeaseKey coordinates one catalog publisher group. DefaultLeaseKey = "starmap-catalog-sync" // DefaultLeaseTTL bounds an abandoned renewable lease implementation. DefaultLeaseTTL = 15 * time.Minute )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AlertSeverity ¶
type AlertSeverity string
AlertSeverity is the operational priority of a freshness alert.
const ( // AlertSeverityWarning identifies ready-but-degraded state. AlertSeverityWarning AlertSeverity = "warning" // AlertSeverityCritical identifies state that fails readiness. AlertSeverityCritical AlertSeverity = "critical" )
type AttemptRecord ¶
type AttemptRecord struct {
Number int
StartedAt time.Time
CompletedAt time.Time
Duration time.Duration
Status AttemptStatus
RetryClass RetryClass
RetryDelay time.Duration
FailureType string
}
AttemptRecord is the durable, secret-safe result of one Sync invocation.
func (AttemptRecord) Validate ¶
func (a AttemptRecord) Validate() error
Validate verifies a complete terminal attempt record.
type AttemptStatus ¶
type AttemptStatus string
AttemptStatus is the terminal result of one Sync invocation.
const ( // AttemptStatusSucceeded means Sync returned without error. AttemptStatusSucceeded AttemptStatus = "succeeded" // AttemptStatusFailed means Sync returned an error. AttemptStatusFailed AttemptStatus = "failed" )
type BaselineReadiness ¶
BaselineReadiness is the non-startup catalog/freshness readiness supplied by the deployment composition root.
type BaselineReadinessProbe ¶
type BaselineReadinessProbe func() BaselineReadiness
BaselineReadinessProbe evaluates the current catalog/freshness baseline.
type CatalogIdentity ¶
type CatalogIdentity struct {
GenerationID string `json:"generation_id"`
Sequence uint64 `json:"sequence"`
}
CatalogIdentity is the atomic immutable-catalog identity supplied by the deployment composition root when operational state is evaluated.
type CurrentGenerationReader ¶
type CurrentGenerationReader interface {
CurrentGenerationID() string
}
CurrentGenerationReader supplies the base generation observed at run start.
type FilesystemLease ¶
type FilesystemLease struct {
// contains filtered or unexported fields
}
FilesystemLease coordinates scheduler processes that share one filesystem root.
func NewFilesystemLease ¶
func NewFilesystemLease(root string) (*FilesystemLease, error)
NewFilesystemLease creates a shared-filesystem lease adapter.
func (*FilesystemLease) Acquire ¶
func (l *FilesystemLease) Acquire(ctx context.Context, request LeaseRequest) (LeaseGuard, error)
Acquire takes a non-blocking OS-backed lock before provider work.
type FreshnessAlert ¶
type FreshnessAlert struct {
Code string `json:"code"`
Severity AlertSeverity `json:"severity"`
Source catalogmeta.SourceID `json:"source"`
Message string `json:"message"`
}
FreshnessAlert is one machine-readable operator signal.
type FreshnessMonitor ¶
type FreshnessMonitor struct {
// contains filtered or unexported fields
}
FreshnessMonitor retains only the newest validated observation per configured source and evaluates it against explicit deployment SLAs.
func NewFreshnessMonitor ¶
func NewFreshnessMonitor(policy FreshnessPolicy) (*FreshnessMonitor, error)
NewFreshnessMonitor creates an empty fail-closed monitor.
func (*FreshnessMonitor) Record ¶
func (m *FreshnessMonitor) Record(observations []catalogs.SourceObservationLink) error
Record advances configured sources without allowing out-of-order completion to regress their latest observation.
func (*FreshnessMonitor) RecordManifest ¶
func (m *FreshnessMonitor) RecordManifest(manifest catalogs.GenerationManifest) error
RecordManifest seeds freshness from a validated catalog generation.
func (*FreshnessMonitor) RecordResult ¶
func (m *FreshnessMonitor) RecordResult(result *pkgsync.Result) error
RecordResult advances source freshness from a completed Sync result. It does not require catalog changes or a newly published generation.
func (*FreshnessMonitor) RecordRuns ¶
func (m *FreshnessMonitor) RecordRuns(records []RunRecord) error
RecordRuns restores no-change and published source observations from durable run history. Input order does not matter because older observations cannot replace newer state.
func (*FreshnessMonitor) Report ¶
func (m *FreshnessMonitor) Report(at time.Time) (FreshnessReport, error)
Report evaluates source ages at an explicit UTC instant. Missing required sources and future observations fail readiness; optional missing sources and warning-threshold/degraded observations preserve readiness but degrade it.
type FreshnessPolicy ¶
type FreshnessPolicy struct {
Sources []SourceFreshnessSLA
}
FreshnessPolicy is the explicit set of sources a deployment monitors.
type FreshnessReport ¶
type FreshnessReport struct {
EvaluatedAt time.Time `json:"evaluated_at"`
Ready bool `json:"ready"`
Degraded bool `json:"degraded"`
Sources []SourceFreshness `json:"sources"`
Alerts []FreshnessAlert `json:"alerts,omitempty"`
}
FreshnessReport is the deterministic readiness/degradation decision for all configured sources.
func (FreshnessReport) Copy ¶
func (r FreshnessReport) Copy() FreshnessReport
Copy returns a report with caller-owned collection state.
type FreshnessState ¶
type FreshnessState string
FreshnessState is one source's current SLA disposition.
const ( // FreshnessStateFresh is within budget with a complete successful observation. FreshnessStateFresh FreshnessState = "fresh" // FreshnessStateDegraded remains ready but requires operator attention. FreshnessStateDegraded FreshnessState = "degraded" // FreshnessStateUnready exceeded a critical SLA or has a future timestamp. FreshnessStateUnready FreshnessState = "unready" // FreshnessStateMissing has not observed the configured source. FreshnessStateMissing FreshnessState = "missing" )
type InitialRunController ¶
type InitialRunController struct {
// contains filtered or unexported fields
}
InitialRunController executes exactly one startup policy decision and owns coalescing with the first scheduled tick. It owns no ticker or cadence.
func NewInitialRunController ¶
func NewInitialRunController(runner *Runner, policy InitialRunPolicy, baseline BaselineReadinessProbe) (*InitialRunController, error)
NewInitialRunController creates a passive startup policy controller.
func (*InitialRunController) Readiness ¶
func (c *InitialRunController) Readiness() InitialRunReadiness
Readiness combines the mode's startup gate with the deployment's current baseline readiness. Background pending/failure can serve only an already ready baseline and is explicitly degraded.
func (*InitialRunController) RunScheduledAt ¶
func (c *InitialRunController) RunScheduledAt(ctx context.Context, dueAt time.Time, jitterWindow time.Duration, options ...pkgsync.Option) (RunResult, error)
RunScheduledAt executes a deployment-supplied tick. A tick whose due time is covered by an in-flight or successful startup attempt is durably coalesced; failed startup attempts never suppress the recovery tick.
type InitialRunMode ¶
type InitialRunMode string
InitialRunMode selects the deployment's explicit startup behavior.
const ( // InitialRunStartupBlocking runs Sync before startup can complete. InitialRunStartupBlocking InitialRunMode = "startup_blocking" // InitialRunStartupBackground runs Sync asynchronously while an existing // ready baseline may continue serving in degraded startup state. InitialRunStartupBackground InitialRunMode = "startup_background" // InitialRunScheduleOnly performs no startup Sync and waits for cadence. InitialRunScheduleOnly InitialRunMode = "schedule_only" )
type InitialRunPolicy ¶
type InitialRunPolicy struct {
Mode InitialRunMode
CoalesceWindow time.Duration
}
InitialRunPolicy defines startup mode and the bounded interval in which a successful/running startup attempt replaces the first scheduled tick.
func (InitialRunPolicy) Validate ¶
func (p InitialRunPolicy) Validate() error
Validate verifies an explicit mode and bounded coalescing policy.
type InitialRunReadiness ¶
type InitialRunReadiness struct {
Mode InitialRunMode `json:"mode"`
State InitialRunState `json:"state"`
Ready bool `json:"ready"`
Degraded bool `json:"degraded"`
IssueCode string `json:"issue_code,omitempty"`
RunID string `json:"run_id,omitempty"`
FailureType string `json:"failure_type,omitempty"`
}
InitialRunReadiness combines explicit startup state with the supplied catalog/freshness baseline.
type InitialRunState ¶
type InitialRunState string
InitialRunState is the lifecycle of the one startup decision.
const ( InitialRunStatePending InitialRunState = "pending" InitialRunStateRunning InitialRunState = "running" InitialRunStateSucceeded InitialRunState = "succeeded" InitialRunStateFailed InitialRunState = "failed" InitialRunStateLeaseHeld InitialRunState = "lease_held" InitialRunStateScheduleOnly InitialRunState = "schedule_only" )
Initial run lifecycle states.
type Lease ¶
type Lease interface {
Acquire(context.Context, LeaseRequest) (LeaseGuard, error)
}
Lease coordinates independent scheduler replicas before provider work.
type LeaseGuard ¶
LeaseGuard owns one acquired lease until Release.
type LeaseRequest ¶
LeaseRequest identifies one scheduler owner and bounded acquisition.
func (LeaseRequest) Validate ¶
func (r LeaseRequest) Validate() error
Validate verifies a complete lease request.
type MemoryLease ¶
type MemoryLease struct {
// contains filtered or unexported fields
}
MemoryLease is a process-local reference lease. Sharing one instance across runner replicas models an external atomic lease service in deterministic tests.
func NewMemoryLease ¶
func NewMemoryLease() *MemoryLease
NewMemoryLease creates an empty reference lease service.
func (*MemoryLease) Acquire ¶
func (l *MemoryLease) Acquire(ctx context.Context, request LeaseRequest) (LeaseGuard, error)
Acquire atomically acquires an absent or expired lease.
type MemoryRunLedger ¶
type MemoryRunLedger struct {
// contains filtered or unexported fields
}
MemoryRunLedger is the concurrency-safe reference run-ledger adapter.
func NewMemoryRunLedger ¶
func NewMemoryRunLedger() *MemoryRunLedger
NewMemoryRunLedger creates an empty reference ledger.
func (*MemoryRunLedger) Begin ¶
func (l *MemoryRunLedger) Begin(ctx context.Context, record RunRecord) error
Begin durably models insertion of a running trigger.
func (*MemoryRunLedger) Complete ¶
func (l *MemoryRunLedger) Complete(ctx context.Context, record RunRecord) error
Complete atomically makes a running record terminal.
func (*MemoryRunLedger) RecordAttempt ¶
func (l *MemoryRunLedger) RecordAttempt(ctx context.Context, runID string, attempt AttemptRecord) error
RecordAttempt appends one contiguous attempt to a running record.
type OperationalRun ¶
type OperationalRun struct {
ID string `json:"id"`
Trigger Trigger `json:"trigger"`
Status RunStatus `json:"status"`
StartedAt time.Time `json:"started_at"`
CompletedAt time.Time `json:"completed_at"`
DurationSeconds float64 `json:"duration_seconds"`
Attempts int `json:"attempts"`
BaseGenerationID string `json:"base_generation_id,omitempty"`
PublishedGenerationID string `json:"published_generation_id,omitempty"`
SyncRunID string `json:"sync_run_id,omitempty"`
FailureType string `json:"failure_type,omitempty"`
}
OperationalRun is the secret-safe endpoint projection of the latest actual synchronization attempt.
type OperationalState ¶
type OperationalState struct {
EvaluatedAt time.Time `json:"evaluated_at"`
Catalog CatalogIdentity `json:"catalog"`
Freshness *FreshnessReport `json:"freshness,omitempty"`
LastSync *OperationalRun `json:"last_sync,omitempty"`
DegradedSources []catalogmeta.SourceID `json:"degraded_sources"`
Scheduler SchedulerOperationalState `json:"scheduler"`
}
OperationalState is one internally consistent operator view of catalog identity, source freshness, the last actual sync, and scheduler lifecycle.
type Operations ¶
type Operations struct {
// contains filtered or unexported fields
}
Operations composes deployment-owned scheduler telemetry without owning a ticker, cadence, or synchronization lifecycle.
func NewOperations ¶
func NewOperations(options ...OperationsOption) (*Operations, error)
NewOperations creates an operational-state composer. With no options it explicitly reports an unconfigured scheduler rather than inventing state.
func (*Operations) State ¶
func (o *Operations) State(ctx context.Context, identity CatalogIdentity) (OperationalState, error)
State evaluates all configured operational inputs at one UTC instant.
type OperationsOption ¶
type OperationsOption func(*Operations) error
OperationsOption configures optional scheduler telemetry inputs.
func WithOperationsClock ¶
func WithOperationsClock(now func() time.Time) OperationsOption
WithOperationsClock supplies the evaluation clock used by operational and freshness reports. Deployments normally omit it; deterministic compositions and tests may share their scheduler clock.
func WithOperationsFreshness ¶
func WithOperationsFreshness(monitor *FreshnessMonitor) OperationsOption
WithOperationsFreshness exposes the configured source SLA report.
func WithOperationsInitialRun ¶
func WithOperationsInitialRun(controller *InitialRunController) OperationsOption
WithOperationsInitialRun exposes the explicit startup lifecycle.
func WithOperationsRunLedger ¶
func WithOperationsRunLedger(ledger RunLedger) OperationsOption
WithOperationsRunLedger exposes durable scheduler history.
type RetryClass ¶
type RetryClass string
RetryClass is the scheduling disposition of a synchronization error.
const ( // RetryClassTransient permits a bounded retry. RetryClassTransient RetryClass = "transient" // RetryClassPermanent ends the attempt sequence immediately. RetryClassPermanent RetryClass = "permanent" )
func ClassifyRetry ¶
func ClassifyRetry(err error) RetryClass
ClassifyRetry permits only explicitly transient failures.
type RetryPolicy ¶
type RetryPolicy struct {
MaxAttempts int
BaseDelay time.Duration
MaxDelay time.Duration
JitterFraction float64
}
RetryPolicy defines bounded exponential retry with proportional jitter.
func DefaultRetryPolicy ¶
func DefaultRetryPolicy() RetryPolicy
DefaultRetryPolicy returns one immediate attempt and no implicit retries.
func (RetryPolicy) Validate ¶
func (p RetryPolicy) Validate() error
Validate verifies a finite bounded retry policy.
type RunLedger ¶
type RunLedger interface {
Begin(context.Context, RunRecord) error
RecordAttempt(context.Context, string, AttemptRecord) error
Complete(context.Context, RunRecord) error
Get(context.Context, string) (RunRecord, error)
List(context.Context, RunQuery) ([]RunRecord, error)
}
RunLedger persists scheduler lifecycle state. Begin precedes lease acquisition, RecordAttempt follows each Sync call, and Complete is terminal.
type RunRecord ¶
type RunRecord struct {
ID string
Trigger Trigger
LeaseOwner string
BaseGenerationID string
StartedAt time.Time
CompletedAt time.Time
Duration time.Duration
Status RunStatus
Attempts []AttemptRecord
SourceObservations []catalogs.SourceObservationLink
PublishedGenerationID string
SyncRunID string
FailureType string
}
RunRecord is one queryable deployment trigger and its publication result. FailureType records only the Go error type; provider error text is excluded because it may contain credentials or response data.
func (RunRecord) ValidateBegin ¶
ValidateBegin verifies the immutable fields of a newly triggered run.
func (RunRecord) ValidateComplete ¶
ValidateComplete verifies a terminal run and its ordered attempts.
type RunResult ¶
type RunResult struct {
Status RunStatus
RunID string
LeaseOwner string
Sync *sync.Result
// Attempts is the number of Sync calls made while holding the lease.
Attempts int
// RetryDelays is a caller-owned record of completed backoff decisions.
RetryDelays []time.Duration
// AttemptRecords contains caller-owned, secret-safe attempt audit metadata.
AttemptRecords []AttemptRecord
}
RunResult reports whether this replica executed provider work.
type RunStatus ¶
type RunStatus string
RunStatus is the disposition of one deployment trigger.
const ( // RunStatusRunning means a durable trigger has begun but is not terminal. RunStatusRunning RunStatus = "running" // RunStatusSucceeded means this replica acquired the lease and sync returned successfully. RunStatusSucceeded RunStatus = "succeeded" // RunStatusFailed means this replica acquired the lease and sync failed. RunStatusFailed RunStatus = "failed" // RunStatusSkippedLeaseHeld means another replica already owns the publisher lease. RunStatusSkippedLeaseHeld RunStatus = "skipped_lease_held" // RunStatusSkippedInitialRun means a startup attempt already covers this tick. RunStatusSkippedInitialRun RunStatus = "skipped_initial_run" // RunStatusSkippedScheduleOnly means startup policy deliberately made no attempt. RunStatusSkippedScheduleOnly RunStatus = "skipped_schedule_only" )
type Runner ¶
type Runner struct {
// contains filtered or unexported fields
}
Runner serializes one explicit synchronization attempt through a deployment lease.
func NewRunner ¶
func NewRunner(syncer Syncer, lease Lease, request LeaseRequest, options ...RunnerOption) (*Runner, error)
NewRunner creates a deployment-owned synchronization runner.
func (*Runner) RunOnce ¶
RunOnce acquires the publisher lease before invoking Sync. Lease contention is a successful skipped disposition, not a provider failure.
func (*Runner) RunScheduledOnce ¶
func (r *Runner) RunScheduledOnce(ctx context.Context, jitterWindow time.Duration, options ...sync.Option) (RunResult, error)
RunScheduledOnce applies bounded pre-acquisition jitter, then executes the same leased attempt sequence as RunOnce. Manual callers use RunOnce directly.
type RunnerOption ¶
RunnerOption configures deployment retry policy.
func WithFreshnessMonitor ¶
func WithFreshnessMonitor(monitor *FreshnessMonitor) RunnerOption
WithFreshnessMonitor records successful source observations even when the canonical catalog payload does not change.
func WithRetryPolicy ¶
func WithRetryPolicy(policy RetryPolicy) RunnerOption
WithRetryPolicy configures bounded typed retry for one runner.
func WithRunLedger ¶
func WithRunLedger(ledger RunLedger, current CurrentGenerationReader) RunnerOption
WithRunLedger enables durable run auditing and base-generation capture.
type SQLRunLedger ¶
type SQLRunLedger struct {
// contains filtered or unexported fields
}
SQLRunLedger persists queryable run and attempt records through database/sql. The baseline statements use SQLite-compatible question-mark bind parameters.
func NewSQLRunLedger ¶
NewSQLRunLedger initializes the durable run-ledger schema.
func (*SQLRunLedger) Begin ¶
func (l *SQLRunLedger) Begin(ctx context.Context, record RunRecord) error
Begin inserts an idempotent running trigger.
func (*SQLRunLedger) Complete ¶
func (l *SQLRunLedger) Complete(ctx context.Context, record RunRecord) error
Complete atomically makes a running record terminal.
func (*SQLRunLedger) RecordAttempt ¶
func (l *SQLRunLedger) RecordAttempt(ctx context.Context, runID string, attempt AttemptRecord) error
RecordAttempt appends an idempotent contiguous attempt to a running record.
type SchedulerOperationalState ¶
type SchedulerOperationalState struct {
Configured bool `json:"configured"`
InitialRun *InitialRunReadiness `json:"initial_run,omitempty"`
}
SchedulerOperationalState reports whether deployment scheduling is wired and, when configured, the explicit startup lifecycle.
type SourceFreshness ¶
type SourceFreshness struct {
Source catalogmeta.SourceID `json:"source"`
Required bool `json:"required"`
ObservationID string `json:"observation_id,omitempty"`
ObservedAt time.Time `json:"observed_at"`
Age time.Duration `json:"-"`
AgeSeconds int64 `json:"age_seconds"`
DegradedAfter time.Duration `json:"-"`
DegradedAfterSeconds int64 `json:"degraded_after_seconds"`
UnreadyAfter time.Duration `json:"-"`
UnreadyAfterSeconds int64 `json:"unready_after_seconds"`
ObservationStatus catalogmeta.ObservationStatus `json:"observation_status,omitempty"`
Completeness catalogmeta.ObservationCompleteness `json:"completeness,omitempty"`
State FreshnessState `json:"state"`
}
SourceFreshness is one source's evaluated observation and SLA state.
type SourceFreshnessSLA ¶
type SourceFreshnessSLA struct {
Source catalogmeta.SourceID
DegradedAfter time.Duration
UnreadyAfter time.Duration
Required bool
}
SourceFreshnessSLA defines warning and readiness budgets for one source.
func (SourceFreshnessSLA) Validate ¶
func (s SourceFreshnessSLA) Validate() error
Validate verifies a useful two-threshold source policy.
type Trigger ¶
type Trigger string
Trigger identifies why a scheduler run was requested.
const ( // TriggerManual is an explicit operator or application request. TriggerManual Trigger = "manual" // TriggerScheduled is a cadence-owned deployment request. TriggerScheduled Trigger = "scheduled" // TriggerStartup is an initial-run policy request. TriggerStartup Trigger = "startup" // TriggerAPI is a request received through a remote control plane. TriggerAPI Trigger = "api" )