pub struct SyncEngine { /* private fields */ }Expand description
Decides when each registered target runs.
Implementations§
Source§impl SyncEngine
impl SyncEngine
pub fn new( storage: Arc<dyn Storage>, clock: Arc<dyn Clock>, events: EventBus, ) -> Self
Sourcepub fn register(
&self,
target: SyncTarget,
policy: SyncPolicy,
source: Arc<dyn SyncSource>,
)
pub fn register( &self, target: SyncTarget, policy: SyncPolicy, source: Arc<dyn SyncSource>, )
Register a target. Registering the same target again replaces it.
Synchronous so that a module can register from ApplicationModule::register,
which runs during startup and has no runtime to await on.
Sourcepub fn unregister(&self, target: &SyncTarget)
pub fn unregister(&self, target: &SyncTarget)
Stop tracking a target. Any run in flight is cancelled.
pub fn targets(&self) -> Vec<SyncTarget>
Sourcepub fn policy(&self, target: &SyncTarget) -> Option<SyncPolicy>
pub fn policy(&self, target: &SyncTarget) -> Option<SyncPolicy>
The policy a target was registered with.
pub async fn state(&self, target: &SyncTarget) -> Result<SyncState>
Sourcepub async fn due_at(&self, target: &SyncTarget) -> Result<OffsetDateTime>
pub async fn due_at(&self, target: &SyncTarget) -> Result<OffsetDateTime>
When this target may next run.
Healthy targets follow their interval; failing ones follow the backoff; an offline machine gets the flat offline retry instead of an exponential one.
Sourcepub async fn run_due(
&self,
now: OffsetDateTime,
) -> Vec<(SyncTarget, Result<SyncOutcome>)>
pub async fn run_due( &self, now: OffsetDateTime, ) -> Vec<(SyncTarget, Result<SyncOutcome>)>
Sync every target that is due at now.
Separate from the background loop so scheduling can be tested by moving a fake clock instead of by sleeping.
Sourcepub async fn sync_if_due(
&self,
target: &SyncTarget,
) -> Result<Option<SyncOutcome>>
pub async fn sync_if_due( &self, target: &SyncTarget, ) -> Result<Option<SyncOutcome>>
Sync unless the target ran very recently.
This is the entry point for triggers that fire on their own — window focus, network coming back, a view being opened. Without the throttle, alt-tabbing twenty times means twenty syncs.
Returns Ok(None) when the run was skipped. A user pressing Refresh should
go through SyncEngine::sync_now instead: they asked explicitly.
Sourcepub async fn sync_now(&self, target: &SyncTarget) -> Result<SyncOutcome>
pub async fn sync_now(&self, target: &SyncTarget) -> Result<SyncOutcome>
Sync one target immediately, whatever the throttle says.
Single-flight: a second caller waits for the run in flight instead of starting a parallel one. Two concurrent syncs of the same target would race on the validators and could store an older result over a newer one.
Sourcepub async fn health(&self) -> Health
pub async fn health(&self) -> Health
Health across all registered targets — the worst state wins.
Sourcepub async fn health_of_account(
&self,
connector: &ConnectorId,
account: &AccountId,
) -> Health
pub async fn health_of_account( &self, connector: &ConnectorId, account: &AccountId, ) -> Health
Health of everything belonging to one account.
Sourcepub async fn run(&self, stop: CancellationToken)
pub async fn run(&self, stop: CancellationToken)
Run the scheduler until stop is cancelled.
Returns a future rather than spawning a task: which executor runs it, and on
which thread, is the host’s decision. A platform crate that called
tokio::spawn itself would panic wherever no runtime is entered — which is
exactly what a Tauri setup hook is.
A thin wrapper around SyncEngine::run_due; all the logic worth testing is
in there, not in this loop.
Source§impl SyncEngine
Convenience for the common “every interval” registration.
impl SyncEngine
Convenience for the common “every interval” registration.
pub fn register_every( &self, target: SyncTarget, interval: Duration, source: Arc<dyn SyncSource>, )
Trait Implementations§
Source§impl Clone for SyncEngine
impl Clone for SyncEngine
Source§fn clone(&self) -> SyncEngine
fn clone(&self) -> SyncEngine
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more