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 ¶
- func ApplyPullBatch(database *db.DB, events []syncengine.Event, deviceID string, ...) error
- func Pull(database *db.DB, client *syncclient.Client, state *db.SyncState, ...) error
- func Push(database *db.DB, client *syncclient.Client, state *db.SyncState, ...) error
- func PushBatchWithRetry(client *syncclient.Client, projectID string, req *syncclient.PushRequest, ...) (*syncclient.PushResponse, error)
- type Gate
- type Options
- type Result
- type Rung
- type Status
- type Syncer
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 Status ¶
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 (*Syncer) 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 ¶
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 ¶
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 ¶
SetStatusHandler replaces the ladder observer. It is intended for owners such as pkg/monitor that construct a Syncer and then attach their projection.