Skip to main content

SyncDb

Struct SyncDb 

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

SQLite database for sync state and task queue

Implementations§

Source§

impl SyncDb

Source

pub fn open(path: impl AsRef<Path>) -> Result<Self>

Open or create the sync database

Source

pub fn open_in_memory() -> Result<Self>

Open an in-memory database (for testing)

Source

pub fn get_or_create_profile(&self, display_name: &str) -> Result<i32>

Get or create a profile by display name

Source

pub fn get_profile_id(&self, display_name: &str) -> Result<Option<i32>>

Get profile ID by display name

Source

pub fn get_latest_profile(&self) -> Result<Option<(i32, String)>>

Get the most recently synced profile, falling back to most recently created.

Returns (profile_id, display_name) if at least one profile exists.

Source

pub fn update_profile_sync_time(&self, profile_id: i32) -> Result<()>

Update profile’s last sync time

Source

pub fn get_sync_state( &self, profile_id: i32, data_type: &str, ) -> Result<Option<SyncState>>

Get sync state for a profile and data type

Source

pub fn update_sync_state(&self, state: &SyncState) -> Result<()>

Update sync state

Source

pub fn get_backfill_state( &self, profile_id: i32, data_type: &str, ) -> Result<Option<(NaiveDate, NaiveDate, bool)>>

Get backfill state for a profile and data type Returns (frontier_date, target_date, is_complete)

Source

pub fn set_backfill_state( &self, profile_id: i32, data_type: &str, frontier_date: NaiveDate, target_date: NaiveDate, is_complete: bool, ) -> Result<()>

Initialize or update backfill state

Source

pub fn update_backfill_frontier( &self, profile_id: i32, data_type: &str, new_frontier: NaiveDate, ) -> Result<()>

Update backfill frontier (moves the frontier date backward as we sync older data)

Source

pub fn mark_backfill_complete( &self, profile_id: i32, data_type: &str, ) -> Result<()>

Mark backfill as complete

Source

pub fn is_backfill_complete( &self, profile_id: i32, data_type: &str, ) -> Result<bool>

Check if backfill is complete for a data type

Source

pub fn push_task(&self, task: &SyncTask) -> Result<i64>

Push a task to the queue

Source

pub fn pop_task( &self, profile_id: i32, pipeline: Option<SyncPipeline>, ) -> Result<Option<SyncTask>>

Pop the next task from the queue for a profile

Source

pub fn pop_task_by_type( &self, profile_id: i32, task_type: &str, pipeline: Option<SyncPipeline>, ) -> Result<Option<SyncTask>>

Pop the next task for a profile and task type

Source

pub fn mark_task_in_progress(&self, task_id: i64) -> Result<()>

Mark a task as in progress

Source

pub fn mark_task_completed(&self, task_id: i64) -> Result<()>

Mark a task as completed

Source

pub fn mark_task_failed( &self, task_id: i64, error: &str, retry_delay_secs: i64, ) -> Result<()>

Mark a task as failed

Source

pub fn recover_in_progress_tasks(&self) -> Result<u32>

Recover in-progress tasks (after crash)

Source

pub fn count_pending_tasks( &self, profile_id: i32, pipeline: Option<SyncPipeline>, ) -> Result<u32>

Count pending tasks

Source

pub fn count_tasks_by_status( &self, profile_id: i32, ) -> Result<(u32, u32, u32, u32)>

Count tasks by status

Source

pub fn count_tasks_by_type( &self, profile_id: i32, pipeline: Option<SyncPipeline>, ) -> Result<(u32, u32, u32, u32)>

Count pending/in_progress/failed tasks by type

Returns (activities, gpx, health, performance) counts

Source

pub fn cleanup_completed_tasks(&self, max_age_days: i32) -> Result<u32>

Clean up old completed tasks

Source

pub fn has_health_data( &self, _profile_id: i32, _date: NaiveDate, ) -> Result<bool>

Check if health data exists for a date

Source

pub fn has_performance_data( &self, _profile_id: i32, _date: NaiveDate, ) -> Result<bool>

Check if performance data exists for a date

Source

pub fn reset_failed_tasks(&self) -> Result<u32>

Reset all failed tasks to pending (clear retry delays)

Source

pub fn clear_pending_tasks(&self) -> Result<u32>

Clear all pending and failed tasks

Auto Trait Implementations§

§

impl !Freeze for SyncDb

§

impl !RefUnwindSafe for SyncDb

§

impl Send for SyncDb

§

impl !Sync for SyncDb

§

impl Unpin for SyncDb

§

impl UnsafeUnpin for SyncDb

§

impl !UnwindSafe for SyncDb

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> 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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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