Avoid duplicate syncs

This commit is contained in:
Jon Staab
2026-03-31 06:51:47 -07:00
parent e6eda81920
commit 95c971af1a
8 changed files with 65 additions and 35 deletions
+6 -4
View File
@@ -13,16 +13,18 @@ Members:
## `pub async fn start(self)`
Calls `self.tick` in a loop every 10 seconds.
- Initializes `last_activity_at` from `repo.max_activity_at()` so historical activities are not replayed on restart.
- Calls `self.tick` in a loop every 10 seconds.
## `pub async fn tick(self)`
Iterates over `repo.list_activity` since last run and does the following:
- For `create_relay` activity, create the relay in zooid via `POST /relay`.
- For `update_relay` or `deactivate_relay` activity, update the relay in zooid via `PUT /relay/:id`.
- For `create_relay`, `update_relay`, or `deactivate_relay` activity, sync the relay to zooid.
- Uses `relay.synced` to decide POST vs PUT (not the activity type), so already-synced relays always use PUT even on restart.
- On success, calls `repo.mark_relay_synced` to set `synced = 1`, `status = 'active'`, and clear `sync_error`.
- On failure, calls `repo.fail_relay_sync`.
- All other activity types are ignored (e.g. `fail_relay_sync` must not trigger another sync).
- If unsuccessful, call `repo.fail_relay_sync`.
## `async fn sync_relay(&self, relay: &Relay, is_new: bool)`
+1
View File
@@ -81,6 +81,7 @@ A relay is a nostr relay owned by a `tenant` and hosted by the attached zooid in
- `blossom_enabled` - whether blossom file storage is enabled
- `livekit_enabled` - whether livekit calls are enabled
- `push_enabled` - whether relay push is enabled
- `synced` (private) - whether the relay has been successfully synced to zooid at least once. Used by infra to decide POST vs PUT.
Some attributes persisted to zooid via API have special handling:
+10
View File
@@ -91,6 +91,16 @@ Notes:
- Sets relay status to `inactive`, sets `sync_error`
- Logs activity as `(fail_relay_sync, relay_id)`
## `pub fn mark_relay_synced(&self, relay_id: &str) -> Result<()>`
- Sets `synced = 1`, `status = 'active'`, clears `sync_error`
- No activity log (called by infra after successful sync)
## `pub fn max_activity_at(&self) -> Result<i64>`
- Returns the maximum `created_at` value from the activity table, or 0 if empty
- Used by infra to initialize the since guard on startup
## `pub fn create_invoice(&self, invoice: &Invoice, invoice_items: [&InvoiceItem]) -> Result<()>`
- Saves an `invoice` row and related `invoice_item` rows