High-level sync orchestrator for email, calendar, and contacts.
Manages the full lifecycle of Aurinko's delta-sync model:
- Start or resume a sync session
- Load all updated records (paging automatically)
- Load all deleted record IDs
- Persist the delta tokens for the next run
- Emit telemetry events per batch
Usage
# Full or incremental email sync
{:ok, result} = Aurinko.Sync.Orchestrator.sync_email(token,
days_within: 30,
on_updated: fn records -> MyApp.Mailbox.upsert_many(records) end,
on_deleted: fn ids -> MyApp.Mailbox.delete_many(ids) end,
get_tokens: fn -> MyApp.Store.get_delta_tokens("email") end,
save_tokens: fn tokens -> MyApp.Store.save_delta_tokens("email", tokens) end
)
# Calendar sync
{:ok, result} = Aurinko.Sync.Orchestrator.sync_calendar(token, "primary",
time_min: ~U[2024-01-01 00:00:00Z],
time_max: ~U[2024-12-31 23:59:59Z],
on_updated: fn records -> MyApp.Calendar.upsert_events(records) end,
on_deleted: fn ids -> MyApp.Calendar.delete_events(ids) end,
get_tokens: fn -> MyApp.Store.get_delta_tokens("calendar:primary") end,
save_tokens: fn tokens -> MyApp.Store.save_delta_tokens("calendar:primary", tokens) end
)
Summary
Functions
Run a full or incremental calendar sync for a given calendar.
Run a full or incremental contacts sync.
Run a full or incremental email sync.
Types
@type sync_opts() :: [ days_within: pos_integer(), on_updated: (list() -> any()), on_deleted: (list() -> any()), get_tokens: (-> map() | nil), save_tokens: (map() -> any()), batch_size: pos_integer() ]
@type sync_result() :: %{ updated: non_neg_integer(), deleted: non_neg_integer(), duration_ms: non_neg_integer(), sync_updated_token: String.t() | nil, sync_deleted_token: String.t() | nil }
Functions
@spec sync_calendar(String.t(), String.t(), sync_opts()) :: {:ok, sync_result()} | {:error, Aurinko.Error.t()}
Run a full or incremental calendar sync for a given calendar.
@spec sync_contacts(String.t(), sync_opts()) :: {:ok, sync_result()} | {:error, Aurinko.Error.t()}
Run a full or incremental contacts sync.
@spec sync_email(String.t(), sync_opts()) :: {:ok, sync_result()} | {:error, Aurinko.Error.t()}
Run a full or incremental email sync.