mirror of
https://github.com/open-jarvis/OpenJarvis.git
synced 2026-07-30 10:52:15 +00:00
Merge main into feat/release-preparation, resolving conflicts in: - rust/crates/openjarvis-learning: keep both optimize module and new learning modules (heuristic_reward, icl_updater, orchestrator, etc.) - rust/crates/openjarvis-python: keep both optimization PyO3 wrappers and new policy/evolver/reward wrappers - rust/crates/openjarvis-python/lib.rs: register all PyO3 classes - README.md: accept main's version Also fix pre-existing clippy issues from rust-migration-v2: - Replace deprecated std::io::Error::new(ErrorKind::Other, ...) with std::io::Error::other(...) - Move test-only imports into #[cfg(test)] modules - Remove unused imports (GpuInfo, Role, EngineError, futures::stream) - Replace Iterator::last() with next_back() on DoubleEndedIterator - Rename from_str() to parse() to avoid confusion with FromStr trait - Fix s.len() % 2 != 0 → !s.len().is_multiple_of(2) - Convert manual async fn to async fn syntax Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
64 lines
1.9 KiB
Rust
64 lines
1.9 KiB
Rust
//! PyO3 bindings for task scheduler.
|
|
|
|
use pyo3::prelude::*;
|
|
|
|
#[pyclass(name = "SchedulerStore", unsendable)]
|
|
pub struct PySchedulerStore {
|
|
inner: openjarvis_scheduler::SchedulerStore,
|
|
}
|
|
|
|
#[pymethods]
|
|
impl PySchedulerStore {
|
|
#[new]
|
|
#[pyo3(signature = (db_path=":memory:"))]
|
|
fn new(db_path: &str) -> Self {
|
|
Self {
|
|
inner: openjarvis_scheduler::SchedulerStore::new(db_path),
|
|
}
|
|
}
|
|
|
|
fn create_task(&self, name: &str, schedule_type: &str, schedule_value: &str) -> PyResult<String> {
|
|
let st = openjarvis_scheduler::ScheduleType::parse(schedule_type).ok_or_else(|| {
|
|
PyErr::new::<pyo3::exceptions::PyValueError, _>(format!(
|
|
"invalid schedule_type '{}', expected cron/interval/once",
|
|
schedule_type
|
|
))
|
|
})?;
|
|
let task = self.inner.create_task(name, st, schedule_value);
|
|
Ok(serde_json::to_string(&task).unwrap_or_default())
|
|
}
|
|
|
|
fn get_task(&self, id: &str) -> Option<String> {
|
|
self.inner
|
|
.get_task(id)
|
|
.map(|t| serde_json::to_string(&t).unwrap_or_default())
|
|
}
|
|
|
|
fn list_tasks(&self) -> String {
|
|
serde_json::to_string(&self.inner.list_tasks()).unwrap_or_default()
|
|
}
|
|
|
|
fn update_status(&self, id: &str, status: &str) -> PyResult<bool> {
|
|
let s = openjarvis_scheduler::TaskStatus::parse(status).ok_or_else(|| {
|
|
PyErr::new::<pyo3::exceptions::PyValueError, _>(format!(
|
|
"invalid status '{}', expected active/paused/cancelled/completed",
|
|
status
|
|
))
|
|
})?;
|
|
Ok(self.inner.update_status(id, s))
|
|
}
|
|
|
|
fn record_run(&self, id: &str, timestamp: f64) -> bool {
|
|
self.inner.record_run(id, timestamp)
|
|
}
|
|
|
|
fn delete_task(&self, id: &str) -> bool {
|
|
self.inner.delete_task(id)
|
|
}
|
|
}
|
|
|
|
#[pyfunction]
|
|
pub fn parse_cron_next(expr: &str, after: f64) -> Option<f64> {
|
|
openjarvis_scheduler::parse_cron_next(expr, after)
|
|
}
|