Separate command and query
This commit is contained in:
@@ -5,25 +5,26 @@ Infra is a service which polls the database and synchronizes updates to relays t
|
||||
Members:
|
||||
|
||||
- `api_url: String` - the URL of the zooid instance to be managed, from `ZOOID_API_URL`
|
||||
- `repo: Repo`
|
||||
- `query: Query`
|
||||
- `command: Command`
|
||||
|
||||
## `pub fn new(repo: Repo) -> Self`
|
||||
## `pub fn new(query: Query, command: Command) -> Self`
|
||||
|
||||
- Reads environment and populates members
|
||||
|
||||
## `pub async fn start(self)`
|
||||
|
||||
- Initializes `last_activity_at` from `repo.max_activity_at()` so historical activities are not replayed on restart.
|
||||
- Initializes `last_activity_at` from `query.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:
|
||||
Iterates over `query.list_activity` since last run and does the following:
|
||||
|
||||
- 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`.
|
||||
- On success, calls `command.mark_relay_synced` to set `synced = 1`, `status = 'active'`, and clear `sync_error`.
|
||||
- On failure, calls `command.fail_relay_sync`.
|
||||
- All other activity types are ignored (e.g. `fail_relay_sync` must not trigger another sync).
|
||||
|
||||
## `async fn sync_relay(&self, relay: &Relay, is_new: bool)`
|
||||
|
||||
Reference in New Issue
Block a user