Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(cron): look up jobs in both cron.jobs and cron_jobs

Steven Enamakele33cb19f00b8
diff --git a/crates/openhuman-core/src/cron/store.rs b/crates/openhuman-core/src/cron/store.rs
index e85b3495de..1a9bbd1514 100644
--- a/crates/openhuman-core/src/cron/store.rs
+++ b/crates/openhuman-core/src/cron/store.rs
@@ -322,15 +322,16 @@ pub(crate) fn force_next_run_for_test(
let docs = std::sync::Arc::clone(opened.scoped()?.documents());
let job_id = job_id.to_string();
crate::storage::block_on_anyhow(async move {
- let stored = docs
- .get("cron.jobs", &job_id)
- .await?
- .ok_or_else(|| anyhow::anyhow!("no job {job_id}"))?;
- let mut doc = stored.doc;
- doc["next_run_ms"] = serde_json::json!(at.timestamp_millis());
- docs.put("cron.jobs", &job_id, doc, Precondition::None)
- .await?;
- Ok(())
+ for collection in ["cron.jobs", "cron_jobs"] {
+ if let Some(stored) = docs.get(collection, &job_id).await? {
+ let mut doc = stored.doc;
+ doc["next_run_ms"] = serde_json::json!(at.timestamp_millis());
+ docs.put(collection, &job_id, doc, Precondition::None)
+ .await?;
+ return Ok(());
+ }
+ }
+ Err(anyhow::anyhow!("no job {job_id}"))
})
}
diff --git a/crates/openhuman-core/src/cron/store_tests.rs b/crates/openhuman-core/src/cron/store_tests.rs
index e2c193ae92..1aabd5f484 100644
--- a/crates/openhuman-core/src/cron/store_tests.rs
+++ b/crates/openhuman-core/src/cron/store_tests.rs
@@ -266,6 +266,11 @@ fn assert_force_next_run_updates_collection(
})
.unwrap();
+ let before_docs = std::sync::Arc::clone(&docs);
+ let collections_before =
+ crate::storage::block_on_anyhow(async move { before_docs.collections("").await }).unwrap();
+ assert!(collections_before.contains(&collection.to_string()));
+
let next = chrono::DateTime::<Utc>::from_timestamp_millis(456).unwrap();
force_next_run_for_test(&config, "seeded-job", next).unwrap();
@@ -285,7 +290,7 @@ fn assert_force_next_run_updates_collection(
other.is_none(),
"helper must not create or write {other_collection}"
);
- assert_eq!(collections, vec![collection.to_string()]);
+ assert_eq!(collections, collections_before);
}
#[test]