syncdaemon

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StateSchemaVersion = "pinax.sync_daemon.state.v1"
	EventSchemaVersion = "pinax.sync_daemon.event.v1"
	StatusStopped      = "stopped"
	StatusRunning      = "running"
	StatusDegraded     = "degraded"
	StatusStopping     = "stopping"
	StatusConflict     = "conflict_required"
)

Variables

This section is empty.

Functions

func Debounce

func Debounce(ctx context.Context, in <-chan WatchEvent, delay time.Duration) <-chan []WatchEvent

func IgnoreRuntimePath

func IgnoreRuntimePath(path string) bool

func PIDAlive

func PIDAlive(pid int) bool

func SafeEventPath

func SafeEventPath(path string) string

Types

type Backoff

type Backoff struct {
	Base    time.Duration
	Max     time.Duration
	Attempt int
}

func (*Backoff) Next

func (b *Backoff) Next(now time.Time) time.Time

func (*Backoff) Reset

func (b *Backoff) Reset()

type DaemonState

type DaemonState struct {
	SchemaVersion  string `json:"schema_version"`
	Status         string `json:"status"`
	Target         string `json:"target"`
	PID            int    `json:"pid,omitempty"`
	DetectionMode  string `json:"detection_mode"`
	LocalDirty     bool   `json:"local_dirty"`
	LocalHash      string `json:"local_hash,omitempty"`
	RemoteRevision string `json:"remote_revision,omitempty"`
	LastPollAt     string `json:"last_poll_at,omitempty"`
	LastSyncAt     string `json:"last_sync_at,omitempty"`
	LastErrorCode  string `json:"last_error_code,omitempty"`
	NextRetryAt    string `json:"next_retry_at,omitempty"`
	Message        string `json:"message,omitempty"`
	StartedAt      string `json:"started_at,omitempty"`
	UpdatedAt      string `json:"updated_at"`
}

func NewState

func NewState(target string, pid int, mode DetectionMode, status string) DaemonState

type DetectionMode

type DetectionMode string
const (
	DetectionWatch DetectionMode = "watch"
	DetectionScan  DetectionMode = "scan"
)

type EventSink

type EventSink func(SyncDaemonEvent)

EventSink receives the same redacted daemon events that are persisted locally.

type Lock

type Lock struct {
	Path string
	PID  int `json:"pid"`
}

func AcquireOperationLock

func AcquireOperationLock(root, owner string) (Lock, error)

func AcquireRunnerLock

func AcquireRunnerLock(root string) (Lock, error)

func (Lock) Release

func (l Lock) Release()

type Loop

type Loop struct {
	Repo         Repository
	Target       string
	Poller       RemotePoller
	Executor     SyncExecutor
	PollInterval time.Duration
	SyncTimeout  time.Duration
	Backoff      Backoff
	EventSink    EventSink
}

func (*Loop) RunOnce

func (l *Loop) RunOnce(ctx context.Context, localDirty bool, knownRemote string) (DaemonState, error)

func (*Loop) RunOnceWithTrigger

func (l *Loop) RunOnceWithTrigger(ctx context.Context, localDirty bool, knownRemote, trigger string) (DaemonState, error)

type RemotePoller

type RemotePoller interface {
	PollHead(ctx context.Context) (string, error)
}

type Repository

type Repository struct{ Root string }

func NewRepository

func NewRepository(root string) Repository

func (Repository) AppendEvent

func (r Repository) AppendEvent(event SyncDaemonEvent) error

func (Repository) ClearStopRequest

func (r Repository) ClearStopRequest()

func (Repository) Dir

func (r Repository) Dir() string

func (Repository) EventsPath

func (r Repository) EventsPath() string

func (Repository) ReadEvents

func (r Repository) ReadEvents(limit int) ([]SyncDaemonEvent, error)

func (Repository) ReadState

func (r Repository) ReadState() (DaemonState, error)

func (Repository) RequestStop

func (r Repository) RequestStop() error

func (Repository) StatePath

func (r Repository) StatePath() string

func (Repository) StopPath

func (r Repository) StopPath() string

func (Repository) StopRequested

func (r Repository) StopRequested() bool

func (Repository) WriteState

func (r Repository) WriteState(state DaemonState) error

type RunRequest

type RunRequest struct {
	VaultPath    string
	Target       string
	Yes          bool
	Once         bool
	PollInterval time.Duration
	SyncTimeout  time.Duration
	Mode         DetectionMode
}

type SyncDaemonEvent

type SyncDaemonEvent struct {
	SchemaVersion  string         `json:"schema_version"`
	Seq            int            `json:"seq,omitempty"`
	Type           string         `json:"type"`
	Status         string         `json:"status,omitempty"`
	Target         string         `json:"target,omitempty"`
	Path           string         `json:"path,omitempty"`
	ErrorCode      string         `json:"error_code,omitempty"`
	Message        string         `json:"message,omitempty"`
	Facts          map[string]any `json:"facts,omitempty"`
	CycleID        string         `json:"cycle_id,omitempty"`
	Trigger        string         `json:"trigger,omitempty"`
	Direction      string         `json:"direction,omitempty"`
	DurationMS     int64          `json:"duration_ms,omitempty"`
	LocalDirty     bool           `json:"local_dirty,omitempty"`
	RemoteRevision string         `json:"remote_revision,omitempty"`
	RevisionID     string         `json:"revision_id,omitempty"`
	SyncRunID      string         `json:"sync_run_id,omitempty"`
	RemoteWrite    bool           `json:"remote_write,omitempty"`
	LocalWrite     bool           `json:"local_write,omitempty"`
	CreatedAt      string         `json:"created_at"`
}

func NewEvent

func NewEvent(eventType, status, target string) SyncDaemonEvent

func PrepareEvent

func PrepareEvent(event SyncDaemonEvent) SyncDaemonEvent

type SyncExecutor

type SyncExecutor interface {
	Pull(ctx context.Context, remoteRevision string) error
	Push(ctx context.Context) (string, error)
}

type WatchEvent

type WatchEvent struct{ Path string }

type Watcher

type Watcher interface {
	Events() <-chan WatchEvent
	Errors() <-chan error
	Close() error
}

func NewFSNotifyWatcher

func NewFSNotifyWatcher(root string) (Watcher, error)

Jump to

Keyboard shortcuts

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