Documentation
¶
Overview ¶
Package librarysync keeps this device's library converged with the linked Zaparoo Online account while the user has Library sync turned on. Every local feature it touches works without it: sync only uploads what the device already holds and never makes a local list depend on the account.
Index ¶
- Constants
- Variables
- func IsIdleError(err error) bool
- type ClientFactory
- type DecksResult
- type InventoryResult
- type Options
- type Service
- func (s *Service) ApplySetting(ctx context.Context) (bool, error)
- func (s *Service) DeleteInventory(ctx context.Context) (bool, error)
- func (s *Service) Enabled() bool
- func (s *Service) HintNeedsPull(kind string, revision int64) bool
- func (s *Service) PullDecks(ctx context.Context) error
- func (s *Service) PullDecksIfStale(ctx context.Context) error
- func (s *Service) SyncDecks(ctx context.Context) (DecksResult, error)
- func (s *Service) SyncInventory(ctx context.Context, force bool) (InventoryResult, error)
- func (s *Service) SyncState(ctx context.Context) (StateResult, error)
- type StateResult
Constants ¶
const ( // DeviceStateKeyDecksSince is the pull cursor for decks. DeviceStateKeyDecksSince = "library_decks_since" // DeviceStateKeyDecksLink records the endpoint and device link the deck // bookkeeping belongs to. DeviceStateKeyDecksLink = "library_decks_link" )
const ( InventorySkipped = "skipped" InventoryConfirmed = "confirmed" InventoryUploaded = "uploaded" InventoryTooLarge = "too_large" )
Inventory pass outcomes.
const ( // DeviceStateKeyEnabledSeen records the Library sync setting the last // pass acted on, so turning it off is noticed even across a restart or a // hand-edited config file. DeviceStateKeyEnabledSeen = "library_sync_enabled_seen" // DeviceStateKeyInventoryDeletePending records that the account still // holds this device's inventory after Library sync was turned off. DeviceStateKeyInventoryDeletePending = "library_inventory_delete_pending" )
const ( HintKindState = "state" HintKindDecks = "decks" )
Kinds of library data a change hint from the account can name.
const ( // DeviceStateKeyStateSince is the pull cursor for personal state. DeviceStateKeyStateSince = "library_state_since" // DeviceStateKeyStateLink records the endpoint and device link the // personal state bookkeeping belongs to. DeviceStateKeyStateLink = "library_state_link" // DeviceStateKeyStateMatchGeneration is the index generation the last // attempt to find copies of unmatched games ran against. DeviceStateKeyStateMatchGeneration = "library_state_match_generation" )
Variables ¶
var ( // ErrDisabled reports a pass skipped because Library sync is off. ErrDisabled = errors.New("library sync is disabled") // ErrNotSettled reports a pass deferred because the media database is // being indexed or optimized. ErrNotSettled = errors.New("media database is not settled") )
Functions ¶
func IsIdleError ¶
IsIdleError reports an error that means there is nothing to do right now rather than a failure: sync is off, the device is not linked, or the media database is busy or between connections. None of these deserve the failure backoff, because waiting for the next pass is the whole remedy.
Types ¶
type ClientFactory ¶
type ClientFactory func(baseURL string) (*backup.OnlineClient, error)
ClientFactory returns a client for the Library sync endpoint.
type DecksResult ¶
DecksResult summarizes one deck pass.
type InventoryResult ¶
type InventoryResult struct {
Outcome string
Generation int64
ItemCount int
Resolved int
Rejected int
Skipped int
Unanswered int
}
InventoryResult summarizes one inventory pass. Skipped counts present files the walk could not describe at all, so a library whose inventory is smaller than its file count has an answer in the log rather than only a discrepancy. Unanswered counts identities the account returned nothing usable for, which makes the inventory an incomplete description of the library.
type Options ¶
type Options struct {
Config *config.Instance
DB *database.Database
NewClient ClientFactory
Inbox *inbox.Service
Pauser *syncutil.Pauser
// SendHeartbeat reports the device's capabilities, including whether
// Library sync is on, after the setting changes. Optional.
SendHeartbeat func(context.Context) error
// Now returns the current time. Optional.
Now func() time.Time
// Launchers returns the launchers of a system, used to pick the copy a
// launch would start when a pulled flag needs a home. Optional.
Launchers func(systemID string) []platforms.Launcher
// Notifications receives decks.changed when a sync pass changes a deck.
// Optional.
Notifications chan<- models.Notification
// ResolvePace is the least time between resolve requests. Zero uses
// the default.
ResolvePace time.Duration
}
Options configures a Service.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service runs Library sync passes.
func (*Service) ApplySetting ¶
ApplySetting acts on a change of the Library sync setting since the last time it was applied: turning it off marks the device's inventory for deletion, turning it on forces the next pass to check what the account holds, and either way the account is told through a heartbeat. It reports whether the setting had changed.
func (*Service) DeleteInventory ¶
DeleteInventory drops this device's inventory from the account if Library sync was turned off since it was last committed. A device that is no longer linked has nothing left to drop.
func (*Service) Enabled ¶
Enabled reports whether the user has Library sync turned on, so a caller can skip work that only exists to serve it.
func (*Service) HintNeedsPull ¶
HintNeedsPull reports whether a change hint names a write this device has not pulled yet. A hint at or below the pull cursor for its kind is an echo of something already seen; an unknown kind is always worth a pass.
func (*Service) PullDecksIfStale ¶
PullDecksIfStale pulls decks when the last pull is older than the access window, for a client listing them or a deck that just opened.
func (*Service) SyncDecks ¶
func (s *Service) SyncDecks(ctx context.Context) (DecksResult, error)
SyncDecks converges owned decks with the account: pull first so the bases are current, then push what changed here.
func (*Service) SyncInventory ¶
SyncInventory brings the account's copy of this device's inventory up to date with the current index. An index generation already committed is only checked against the account once an hour; force checks it now.