forked from coracle/caravel
1.4 KiB
1.4 KiB
pub struct Infra
Infra is a service which polls the database and synchronizes updates to relays to a remote zooid instance via api_url.
Members:
api_url: String- the URL of the zooid instance to be managed, fromZOOID_API_URLrepo: Repo
pub fn new(repo: Repo) -> Self
- Reads environment and populates members
pub async fn start(self)
- Initializes
last_activity_atfromrepo.max_activity_at()so historical activities are not replayed on restart. - Calls
self.tickin 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,update_relay, ordeactivate_relayactivity, sync the relay to zooid.- Uses
relay.syncedto decide POST vs PUT (not the activity type), so already-synced relays always use PUT even on restart. - On success, calls
repo.mark_relay_syncedto setsynced = 1,status = 'active', and clearsync_error. - On failure, calls
repo.fail_relay_sync.
- Uses
- All other activity types are ignored (e.g.
fail_relay_syncmust not trigger another sync).
async fn sync_relay(&self, relay: &Relay, is_new: bool)
- If
is_new, sendsPOST /relay/:idto create the relay in zooid. - Otherwise, sends
PUT /relay/:idto update it. - Passes full relay configuration in the body including host, schema, secret, inactive flag, info, policy, groups, management, blossom, livekit, push, and roles.