Migrate test plugins to Rust and async-ify syscall modules
- Replace Python test plugins (echo, ai_test, claudecode) with Rust implementations driven by the plugin SDK - Convert fs/network/process/timer syscall modules to async/await - Change Network.OpenConn to return stream ConnEvent (conn_id handed to client in first "open" frame for Send/Close routing) - Bind timer callbacks to plugin identity; stream_call subscriptions are identity-checked - Update docs and regenerate Python SDK protobuf stubs Verified: cargo build/test/clippy clean; echo + ai_test full syscall suites pass; hermes & claudecode register and heartbeat; cross-plugin bridge.call routing and auth denial verified end-to-end. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use std::collections::HashMap;
|
||||
use std::str::FromStr;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use tokio::time::{self, Duration};
|
||||
|
||||
@@ -75,4 +76,53 @@ impl TimerSyscall {
|
||||
.unwrap_or_default()
|
||||
.as_millis() as i64
|
||||
}
|
||||
|
||||
/// Cron 表达式为 cron crate 7 段格式: sec min hour day-of-month month day-of-week year
|
||||
pub fn cron(&self, expr: &str, callback_id: String, plugin_id: String) -> Result<String, String> {
|
||||
let schedule = cron::Schedule::from_str(expr)
|
||||
.map_err(|e| format!("invalid cron expression: {e}"))?;
|
||||
|
||||
let timer_id = {
|
||||
let mut next = self.next_id.lock().unwrap();
|
||||
let id = format!("cron_{}", *next);
|
||||
*next += 1;
|
||||
id
|
||||
};
|
||||
|
||||
let tid = timer_id.clone();
|
||||
let cb = callback_id.clone();
|
||||
let pid = plugin_id.clone();
|
||||
let bus = self.bus.clone();
|
||||
let timers = self.timers.clone();
|
||||
|
||||
let handle = tokio::spawn(async move {
|
||||
loop {
|
||||
let next = schedule.upcoming(chrono::Utc).next();
|
||||
match next {
|
||||
Some(t) => {
|
||||
let dur = (t - chrono::Utc::now())
|
||||
.to_std()
|
||||
.unwrap_or(std::time::Duration::ZERO);
|
||||
tokio::time::sleep(dur).await;
|
||||
bus.fire(
|
||||
&pid,
|
||||
TimerEvent {
|
||||
timer_id: tid.clone(),
|
||||
callback_id: cb.clone(),
|
||||
},
|
||||
);
|
||||
}
|
||||
None => break,
|
||||
}
|
||||
}
|
||||
timers.lock().unwrap().remove(&tid);
|
||||
});
|
||||
|
||||
self.timers
|
||||
.lock()
|
||||
.unwrap()
|
||||
.insert(timer_id.clone(), TimerEntry { handle });
|
||||
|
||||
Ok(timer_id)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user