Skip to main content

SyncEngine

Struct SyncEngine 

Source
pub struct SyncEngine { /* private fields */ }
Expand description

Decides when each registered target runs.

Implementations§

Source§

impl SyncEngine

Source

pub fn new( storage: Arc<dyn Storage>, clock: Arc<dyn Clock>, events: EventBus, ) -> Self

Source

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.

Source

pub fn unregister(&self, target: &SyncTarget)

Stop tracking a target. Any run in flight is cancelled.

Source

pub fn targets(&self) -> Vec<SyncTarget>

Source

pub fn policy(&self, target: &SyncTarget) -> Option<SyncPolicy>

The policy a target was registered with.

Source

pub async fn state(&self, target: &SyncTarget) -> Result<SyncState>

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub async fn health(&self) -> Health

Health across all registered targets — the worst state wins.

Source

pub async fn health_of_account( &self, connector: &ConnectorId, account: &AccountId, ) -> Health

Health of everything belonging to one account.

Source

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.

Source

pub fn register_every( &self, target: SyncTarget, interval: Duration, source: Arc<dyn SyncSource>, )

Trait Implementations§

Source§

impl Clone for SyncEngine

Source§

fn clone(&self) -> SyncEngine

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SyncEngine

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more