tdsync

package
v0.68.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: MIT Imports: 16 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package tdsync owns td's steady-state sync policy and orchestration.

It is safe for long-lived in-process consumers: Once never bootstraps or replaces issues.db, and callers may supply the database handle they already own.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyPullBatch

func ApplyPullBatch(database *db.DB, events []syncengine.Event, deviceID string, lastServerSeq int64, lastSyncAt *time.Time, baseDir string) error

ApplyPullBatch is retained for focused command compatibility tests.

func Pull

func Pull(database *db.DB, client *syncclient.Client, state *db.SyncState, deviceID, baseDir string) error

Pull is retained for focused command compatibility tests.

func Push

func Push(database *db.DB, client *syncclient.Client, state *db.SyncState, deviceID, baseDir string) error

Push is retained for the explicit command's focused compatibility tests. New consumers should use Syncer.Once.

func PushBatchWithRetry

func PushBatchWithRetry(client *syncclient.Client, projectID string, req *syncclient.PushRequest, deadline time.Time) (*syncclient.PushResponse, error)

PushBatchWithRetry is retained for focused command compatibility tests.

Types

type Gate

type Gate struct {
	Open          bool   `json:"open"`
	Authenticated bool   `json:"authenticated"`
	Configured    bool   `json:"configured"`
	KillSwitch    bool   `json:"kill_switch"`
	Reason        string `json:"reason"`
	Source        string `json:"source"`
}

Gate is the complete steady-state sync decision for a project.

type Options

type Options struct {
	BaseDir string
	DB      *db.DB
	Logger  *slog.Logger
	// Interval controls probing and timed fallback cadence. Zero uses td's
	// configured autosync interval.
	Interval time.Duration
	// OnStatus receives ladder transitions and sync outcomes. Callbacks run on
	// the live-sync goroutine and should return promptly.
	OnStatus func(Status)
}

Options configures one project's Syncer. DB is optional; when present, the caller retains ownership and Syncer never closes it.

type Result

type Result struct {
	Pushed    int   `json:"pushed"`
	Pulled    int   `json:"pulled"`
	Pending   int64 `json:"pending"`
	Conflicts int   `json:"conflicts"`
}

Result summarizes one push-and-pull round trip.

type Rung

type Rung string

Rung identifies the active live-sync transport or terminal gate state.

const (
	RungLive    Rung = "live"
	RungProbing Rung = "probing"
	RungTimed   Rung = "timed"
	RungOff     Rung = "off"
	RungExpired Rung = "expired"
)

type Status

type Status struct {
	Rung   Rung
	Gate   Gate
	Result Result
	Error  error
	Reason string
}

Status is one observable live-sync outcome. Result is populated for a completed push/pull pass. Error describes the transport failure that caused a degradation; it is not sticky after a later successful outcome.

type Syncer

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

Syncer owns one project's steady-state sync lifecycle.

func New

func New(opts Options) (*Syncer, error)

New constructs a Syncer without opening a database or doing network work.

func (*Syncer) Gate

func (s *Syncer) Gate() Gate

Gate resolves the one sync gate used by commands and in-process consumers. It never returns an error; unavailable state closes the gate with a reason.

func (*Syncer) Live

func (s *Syncer) Live(ctx context.Context, onChange func()) error

Live owns steady-state cadence for one project. It performs an initial push/pull, prefers SSE refresh hints, degrades through cheap status probes to timed full sync, and stops all network traffic after an exact 401 until the server/key/project fingerprint changes. onChange means pulled data changed the local database; consumers should refresh their projection.

func (*Syncer) Once

func (s *Syncer) Once(ctx context.Context) (Result, error)

Once runs one push-and-optional-pull round trip. Concurrent callers share the same in-flight result. It never performs snapshot bootstrap or replaces the database file.

func (*Syncer) RequestSync

func (s *Syncer) RequestSync()

RequestSync asks a running Live ladder to perform a prompt pass. Requests coalesce while a pass is already pending, which is appropriate for monitor mutations: the database is the queue and Once drains it.

func (*Syncer) SetStatusHandler

func (s *Syncer) SetStatusHandler(handler func(Status))

SetStatusHandler replaces the ladder observer. It is intended for owners such as pkg/monitor that construct a Syncer and then attach their projection.

Jump to

Keyboard shortcuts

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