chore(v1.1.9): clippy clean — workspace -D warnings
Surfaced + fixed during the F3 attestation:
- executor-core/sdk/queue.rs: drop redundant .map(|()| ()) call sites;
enqueue_blocking discards QueueMessageId via .map(|_id| ()) (intentional)
- executor-core/sdk/retry.rs: hoist use std::collections::hash_map::DefaultHasher
+ use std::hash::Hasher to the top of the file (clippy::items_after_statements);
replace `as i64` casts with i64::try_from + clear comment about jitter
bound (clippy::cast_possible_wrap)
- executor-core/sdk/invoke.rs: move _LIMITS_IS_COPY const before #[cfg(test)]
mod tests (clippy::items_after_test_module)
- manager-core/dispatcher.rs: dispatch_one_queue gains #[allow(too_many_lines)]
(it's the queue tick's whole logic — split makes it less readable than
the lint); .map(...).unwrap_or(default) → .map_or(default, ...)
- picloud/lib.rs: Limits { trigger_depth_max, ..Limits::default() } via
struct-update instead of let-mut-assign (clippy::field_reassign_with_default)
- tests: r#"..."# → r"..." where there are no `"` inside (clippy::needless_raw_string_hashes);
combine InvokeTarget::Name | InvokeTarget::Path arms with identical bodies
in sdk_invoke.rs (clippy::match_same_arms)
cargo fmt --all -- --check 2>&1 | tail -3: no output (exit 0)
cargo clippy --workspace --all-targets --all-features -- -D warnings:
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.41s
Workspace lib smoke: 432 passing (306 manager-core + 74 executor-core + 34 shared + 18 orchestrator-core).
DB-gated E2E (against docker compose postgres on localhost:15432):
queue_e2e: 4 ok / invoke_e2e: 4 ok / retry_e2e: 3 ok / migration_queue_messages: 4 ok / schema_snapshot: 1 ok
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -195,7 +195,13 @@ impl Engine {
|
||||
);
|
||||
engine.set_module_resolver(resolver);
|
||||
let self_engine = self.self_arc();
|
||||
sdk::register_all(&mut engine, &self.services, cx, effective_limits, self_engine);
|
||||
sdk::register_all(
|
||||
&mut engine,
|
||||
&self.services,
|
||||
cx,
|
||||
effective_limits,
|
||||
self_engine,
|
||||
);
|
||||
|
||||
let mut scope = Scope::new();
|
||||
scope.push_constant("ctx", build_ctx_map(&req));
|
||||
|
||||
@@ -257,7 +257,9 @@ fn args_to_json(value: &Dynamic) -> Result<Json, Box<EvalAltResult>> {
|
||||
return Ok(serde_json::Number::from_f64(f).map_or(Json::Null, Json::Number));
|
||||
}
|
||||
if value.is_string() {
|
||||
return Ok(Json::String(value.clone().into_string().unwrap_or_default()));
|
||||
return Ok(Json::String(
|
||||
value.clone().into_string().unwrap_or_default(),
|
||||
));
|
||||
}
|
||||
if let Some(arr) = value.clone().try_cast::<Array>() {
|
||||
let mut out = Vec::with_capacity(arr.len());
|
||||
@@ -276,6 +278,14 @@ fn args_to_json(value: &Dynamic) -> Result<Json, Box<EvalAltResult>> {
|
||||
Ok(Json::String(value.to_string()))
|
||||
}
|
||||
|
||||
/// `Limits` is `Copy`; passed by value into `register` so closures take
|
||||
/// owned copies. Hint for readers wondering why it doesn't need `Arc`.
|
||||
#[allow(dead_code)]
|
||||
const _LIMITS_IS_COPY: fn() = || {
|
||||
fn assert_copy<T: Copy>() {}
|
||||
assert_copy::<Limits>();
|
||||
};
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -320,11 +330,3 @@ mod tests {
|
||||
assert_eq!(j, serde_json::json!({ "x": 42 }));
|
||||
}
|
||||
}
|
||||
|
||||
/// `Limits` is `Copy`; passed by value into `register` so closures take
|
||||
/// owned copies. Hint for readers wondering why it doesn't need `Arc`.
|
||||
#[allow(dead_code)]
|
||||
const _LIMITS_IS_COPY: fn() = || {
|
||||
fn assert_copy<T: Copy>() {}
|
||||
assert_copy::<Limits>();
|
||||
};
|
||||
|
||||
@@ -37,7 +37,7 @@ pub(super) fn register(engine: &mut RhaiEngine, services: &Services, cx: Arc<Sdk
|
||||
"enqueue",
|
||||
move |name: &str, message: Dynamic| -> Result<(), Box<EvalAltResult>> {
|
||||
let json = message_to_json(&message)?;
|
||||
enqueue_blocking(&svc, &cx, name, json, EnqueueOpts::default()).map(|_| ())
|
||||
enqueue_blocking(&svc, &cx, name, json, EnqueueOpts::default())
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -52,7 +52,7 @@ pub(super) fn register(engine: &mut RhaiEngine, services: &Services, cx: Arc<Sdk
|
||||
move |name: &str, message: Dynamic, opts: Map| -> Result<(), Box<EvalAltResult>> {
|
||||
let json = message_to_json(&message)?;
|
||||
let opts = parse_opts(&opts)?;
|
||||
enqueue_blocking(&svc, &cx, name, json, opts).map(|_| ())
|
||||
enqueue_blocking(&svc, &cx, name, json, opts)
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -111,7 +111,7 @@ fn enqueue_blocking(
|
||||
let name = name.to_string();
|
||||
handle
|
||||
.block_on(async move { svc.enqueue(&cx, &name, payload, opts).await })
|
||||
.map(|_| ())
|
||||
.map(|_id| ())
|
||||
.map_err(|err| -> Box<EvalAltResult> {
|
||||
EvalAltResult::ErrorRuntime(format!("queue: {err}").into(), rhai::Position::NONE).into()
|
||||
})
|
||||
@@ -187,7 +187,9 @@ fn message_to_json(value: &Dynamic) -> Result<Json, Box<EvalAltResult>> {
|
||||
return Ok(serde_json::Number::from_f64(f).map_or(Json::Null, Json::Number));
|
||||
}
|
||||
if value.is_string() {
|
||||
return Ok(Json::String(value.clone().into_string().unwrap_or_default()));
|
||||
return Ok(Json::String(
|
||||
value.clone().into_string().unwrap_or_default(),
|
||||
));
|
||||
}
|
||||
if let Some(arr) = value.clone().try_cast::<Array>() {
|
||||
let mut out = Vec::with_capacity(arr.len());
|
||||
|
||||
@@ -31,6 +31,8 @@
|
||||
//! `invoke()`, the inner call gets a fresh cx with `trigger_depth + 1`
|
||||
//! via the invoke bridge — retry doesn't see or interfere with that.
|
||||
|
||||
use std::collections::hash_map::DefaultHasher;
|
||||
use std::hash::Hasher;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
@@ -81,11 +83,7 @@ impl BackoffShape {
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn register(
|
||||
engine: &mut RhaiEngine,
|
||||
_services: &Services,
|
||||
_cx: Arc<SdkCallCx>,
|
||||
) {
|
||||
pub(super) fn register(engine: &mut RhaiEngine, _services: &Services, _cx: Arc<SdkCallCx>) {
|
||||
// Custom type so scripts can pass Policy values around.
|
||||
engine.register_type_with_name::<Policy>("Policy");
|
||||
|
||||
@@ -125,9 +123,10 @@ pub(super) fn register(
|
||||
// not `with` because `with` is a Rhai reserved keyword.
|
||||
module.set_native_fn(
|
||||
"run",
|
||||
move |ctx: NativeCallContext, policy: Policy, fn_ptr: FnPtr| -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
retry_run(&ctx, &policy, &fn_ptr)
|
||||
},
|
||||
move |ctx: NativeCallContext,
|
||||
policy: Policy,
|
||||
fn_ptr: FnPtr|
|
||||
-> Result<Dynamic, Box<EvalAltResult>> { retry_run(&ctx, &policy, &fn_ptr) },
|
||||
);
|
||||
|
||||
engine.register_static_module("retry", module.into());
|
||||
@@ -147,20 +146,16 @@ fn build_policy(opts: rhai::Map) -> Result<Policy, Box<EvalAltResult>> {
|
||||
p.max_attempts = n.clamp(1, 20);
|
||||
}
|
||||
if let Some(v) = opts.get("backoff") {
|
||||
let s = v
|
||||
.clone()
|
||||
.into_string()
|
||||
.map_err(|_| -> Box<EvalAltResult> {
|
||||
EvalAltResult::ErrorRuntime(
|
||||
"retry::policy: backoff must be a string".into(),
|
||||
rhai::Position::NONE,
|
||||
)
|
||||
.into()
|
||||
})?;
|
||||
let s = v.clone().into_string().map_err(|_| -> Box<EvalAltResult> {
|
||||
EvalAltResult::ErrorRuntime(
|
||||
"retry::policy: backoff must be a string".into(),
|
||||
rhai::Position::NONE,
|
||||
)
|
||||
.into()
|
||||
})?;
|
||||
p.backoff = BackoffShape::from_wire(&s).ok_or_else(|| -> Box<EvalAltResult> {
|
||||
EvalAltResult::ErrorRuntime(
|
||||
"retry::policy: backoff must be \"exponential\" | \"linear\" | \"constant\""
|
||||
.into(),
|
||||
"retry::policy: backoff must be \"exponential\" | \"linear\" | \"constant\"".into(),
|
||||
rhai::Position::NONE,
|
||||
)
|
||||
.into()
|
||||
@@ -251,13 +246,16 @@ fn apply_jitter(raw: u32, pct: u32) -> u32 {
|
||||
// Deterministic-enough jitter without pulling rand into a hot path:
|
||||
// pick a small offset from the high bits of attempt's hash. Random
|
||||
// distribution doesn't matter for retry — bounded ± is what we want.
|
||||
use std::collections::hash_map::DefaultHasher;
|
||||
use std::hash::Hasher;
|
||||
let mut h = DefaultHasher::new();
|
||||
h.write_u64(span);
|
||||
h.write_u32(raw);
|
||||
let r = h.finish();
|
||||
let offset = (r % (2 * span + 1)) as i64 - span as i64;
|
||||
// span is bounded by raw*100/100 = raw ≤ u32::MAX, so 2*span+1 fits
|
||||
// in i64 without wrapping. `cast_signed` makes the intent explicit
|
||||
// for clippy::cast_possible_wrap.
|
||||
let modded = r % (2 * span + 1);
|
||||
let offset =
|
||||
i64::try_from(modded).unwrap_or(i64::MAX) - i64::try_from(span).unwrap_or(i64::MAX);
|
||||
let signed = i64::from(raw).saturating_add(offset).max(0);
|
||||
u32::try_from(signed.min(i64::from(u32::MAX))).unwrap_or(u32::MAX)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user