sync

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2026 License: BSD-3-Clause Imports: 28 Imported by: 0

Documentation

Overview

Package sync orchestrates data synchronization from PeeringDB into the local SQLite database using the ent ORM.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitStatusTable

func InitStatusTable(ctx context.Context, db *sql.DB) error

InitStatusTable creates the sync_status table if it doesn't exist. This is not an ent-managed entity; it stores operational metadata via raw SQL.

func RecordSyncComplete

func RecordSyncComplete(ctx context.Context, db *sql.DB, id int64, status SyncStatus) error

RecordSyncComplete updates the sync status row with results.

func RecordSyncStart

func RecordSyncStart(ctx context.Context, db *sql.DB, startedAt time.Time) (int64, error)

RecordSyncStart inserts a new running sync status row and returns its ID.

Types

type SyncStatus

type SyncStatus struct {
	LastSyncAt   time.Time
	Duration     time.Duration
	ObjectCounts map[string]int // type -> count
	Status       string         // "success", "failed", "running"
	ErrorMessage string         // empty on success
}

SyncStatus represents the result of a sync operation.

func GetLastSyncStatus

func GetLastSyncStatus(ctx context.Context, db *sql.DB) (*SyncStatus, error)

GetLastSyncStatus returns the most recent sync status. Returns nil if no sync has been recorded.

type Worker

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

Worker orchestrates PeeringDB data synchronization.

func NewWorker

func NewWorker(pdbClient *peeringdb.Client, entClient *ent.Client, db *sql.DB, cfg WorkerConfig, logger *slog.Logger) *Worker

NewWorker creates a new sync worker.

func (*Worker) HasCompletedSync

func (w *Worker) HasCompletedSync() bool

HasCompletedSync reports whether at least one successful sync has completed. Used for 503 behavior per D-30.

func (*Worker) SetRetryBackoffs

func (w *Worker) SetRetryBackoffs(backoffs []time.Duration)

SetRetryBackoffs overrides the default retry backoff durations. Intended for testing.

func (*Worker) StartScheduler

func (w *Worker) StartScheduler(ctx context.Context, interval time.Duration)

StartScheduler runs periodic sync via time.Ticker per D-22. It runs an initial sync immediately, then syncs on each tick. The scheduler stops when ctx is cancelled per CC-2.

func (*Worker) Sync

func (w *Worker) Sync(ctx context.Context) error

Sync executes a full synchronization from PeeringDB to the local database. It acquires a mutex to prevent concurrent runs and wraps all changes in a single database transaction per D-19.

func (*Worker) SyncWithRetry

func (w *Worker) SyncWithRetry(ctx context.Context) error

SyncWithRetry calls Sync and retries on failure with exponential backoff per D-21.

type WorkerConfig

type WorkerConfig struct {
	IncludeDeleted bool
	IsPrimary      bool
}

WorkerConfig holds configuration for the sync worker.

Jump to

Keyboard shortcuts

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