Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
153 changes: 7 additions & 146 deletions iii-directory/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion iii-directory/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ name = "iii_directory"
path = "src/lib.rs"

[dependencies]
iii-sdk = "=0.16.0-next.2"
iii-sdk = "=0.20.0"
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
arc-swap = "1"
tokio = { version = "1", features = ["rt-multi-thread", "macros", "sync", "signal", "time", "fs", "process"] }
serde = { version = "1", features = ["derive"] }
Expand Down
26 changes: 16 additions & 10 deletions iii-directory/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ use std::sync::atomic::{AtomicU64, Ordering};
use std::sync::Arc;
use std::time::Duration;

use iii_sdk::{IIIError, RegisterFunction, RegisterTriggerInput, TriggerRequest, III};
use iii_sdk::errors::Error;
use iii_sdk::protocol::{RegisterTriggerInput, TriggerRequest};
use iii_sdk::{IIIClient, RegisterFunction};
use serde_json::{json, Value};

use crate::config::{SharedConfig, SkillsConfig, Topology};
Expand Down Expand Up @@ -67,7 +69,7 @@ impl SharedState {
/// Register the `iii-directory` configuration schema with the configuration
/// worker. When `seed` is present, its value is installed as `initial_value`.
/// Otherwise, built-in defaults are seeded only when no stored value exists.
pub async fn register_config(iii: &III, seed: Option<&SkillsConfig>) -> Result<(), String> {
pub async fn register_config(iii: &IIIClient, seed: Option<&SkillsConfig>) -> Result<(), String> {
let mut payload = json!({
"id": CONFIG_ID,
"name": "iii-directory",
Expand All @@ -86,7 +88,7 @@ pub async fn register_config(iii: &III, seed: Option<&SkillsConfig>) -> Result<(

/// Read the live `iii-directory` configuration (env-expanded by the
/// configuration worker).
pub async fn fetch_config(iii: &III) -> Result<SkillsConfig, String> {
pub async fn fetch_config(iii: &IIIClient) -> Result<SkillsConfig, String> {
let value = get_config_value(iii).await?;
if value.is_null() {
tracing::info!("no configuration value found; using built-in default configuration");
Expand All @@ -95,22 +97,22 @@ pub async fn fetch_config(iii: &III) -> Result<SkillsConfig, String> {
SkillsConfig::from_json(&value)
}

async fn should_seed_default_value(iii: &III) -> Result<bool, String> {
async fn should_seed_default_value(iii: &IIIClient) -> Result<bool, String> {
match try_get_config_value(iii).await? {
None => Ok(true),
Some(value) if value.is_null() => Ok(true),
Some(_) => Ok(false),
}
}

async fn get_config_value(iii: &III) -> Result<Value, String> {
async fn get_config_value(iii: &IIIClient) -> Result<Value, String> {
try_get_config_value(iii)
.await?
.ok_or_else(|| format!("configuration `{CONFIG_ID}` not found"))
}

/// Returns `Ok(None)` when the entry does not exist (`NOT_FOUND`).
async fn try_get_config_value(iii: &III) -> Result<Option<Value>, String> {
async fn try_get_config_value(iii: &IIIClient) -> Result<Option<Value>, String> {
match trigger_with_retry(iii, "configuration::get", json!({ "id": CONFIG_ID })).await {
Ok(resp) => Ok(resp.get("value").cloned()),
Err(e) if e.contains("NOT_FOUND") => Ok(None),
Expand Down Expand Up @@ -143,7 +145,7 @@ struct OnConfigChangeResponse {

/// Register the internal config-change handler and bind a `configuration`
/// trigger for `configuration:updated` on the `iii-directory` entry.
pub fn register_config_trigger(iii: &III, state: SharedState) -> Result<(), IIIError> {
pub fn register_config_trigger(iii: &IIIClient, state: SharedState) -> Result<(), Error> {
let st = state.clone();
let engine = iii.clone();
iii.register_function(
Expand All @@ -153,7 +155,7 @@ pub fn register_config_trigger(iii: &III, state: SharedState) -> Result<(), IIIE
let engine = engine.clone();
async move {
on_config_change(&engine, &st).await;
Ok::<OnConfigChangeResponse, IIIError>(OnConfigChangeResponse { ok: true })
Ok::<OnConfigChangeResponse, Error>(OnConfigChangeResponse { ok: true })
}
})
.description(
Expand Down Expand Up @@ -182,7 +184,7 @@ pub fn register_config_trigger(iii: &III, state: SharedState) -> Result<(), IIIE
/// download roots without updating persisted state. Re-fetch the stored
/// value via `configuration::get` instead. Topology changes are refused —
/// the on-disk roots and the auto-download wiring are fixed at boot.
async fn on_config_change(iii: &III, state: &SharedState) {
async fn on_config_change(iii: &IIIClient, state: &SharedState) {
let cfg = match fetch_config(iii).await {
Ok(cfg) => cfg,
Err(e) => {
Expand All @@ -204,7 +206,11 @@ async fn on_config_change(iii: &III, state: &SharedState) {
tracing::info!("iii-directory configuration reloaded (tunable fields applied; caches cleared)");
}

async fn trigger_with_retry(iii: &III, function_id: &str, payload: Value) -> Result<Value, String> {
async fn trigger_with_retry(
iii: &IIIClient,
function_id: &str,
payload: Value,
) -> Result<Value, String> {
let mut last_err = String::new();
for attempt in 1..=CONFIG_RETRIES {
match iii
Expand Down
Loading
Loading