Skip to content

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

feat(cron): add tinyflows cron client

Steven Enamakel42191080183f
diff --git a/crates/openhuman-core/src/cron/client.rs b/crates/openhuman-core/src/cron/client.rs
index e49f398683..c10ea5ccfd 100644
--- a/crates/openhuman-core/src/cron/client.rs
+++ b/crates/openhuman-core/src/cron/client.rs
@@ -248,61 +248,9 @@ where
crate::storage::block_on_anyhow(f(config.clone()))
}
-/// Reading a scope's cron store straight through the module, for tests that
-/// stage a backend and check what an importer or another writer left in it.
#[cfg(test)]
-pub(crate) mod testing {
- use super::*;
- use crate::storage::{Scope, StorageBackend};
- use std::sync::Arc;
- use tinyflows_bus::schedule::types::CronRun;
-
- fn run<T: Send + 'static>(
- backend: &Arc<dyn StorageBackend>,
- scope: &Scope,
- operation: StoreOperation,
- ) -> Result<T>
- where
- T: DeserializeOwned,
- {
- let config = Config::default();
- let scope = DocScope::on_backend(&config, Arc::clone(backend), scope.clone());
- crate::storage::block_on_anyhow(async move { store_in(&config, &scope, operation).await })
- }
-
- pub(crate) fn list_jobs(backend: &Arc<dyn StorageBackend>, scope: &Scope) -> Result<Vec<CronJob>> {
- run(backend, scope, StoreOperation::List)
- }
-
- pub(crate) fn get_job(
- backend: &Arc<dyn StorageBackend>,
- scope: &Scope,
- job_id: &str,
- ) -> Result<CronJob> {
- run(
- backend,
- scope,
- StoreOperation::Get {
- job_id: job_id.to_string(),
- },
- )
- }
-
- pub(crate) fn list_runs(
- backend: &Arc<dyn StorageBackend>,
- scope: &Scope,
- job_id: &str,
- ) -> Result<Vec<CronRun>> {
- run(
- backend,
- scope,
- StoreOperation::ListRuns {
- job_id: job_id.to_string(),
- limit: 50,
- },
- )
- }
-}
+#[path = "client_testing.rs"]
+pub(crate) mod testing;
#[cfg(test)]
#[path = "client_tests.rs"]
diff --git a/crates/openhuman-core/src/cron/client_testing.rs b/crates/openhuman-core/src/cron/client_testing.rs
new file mode 100644
index 0000000000..c0ea5df353
--- /dev/null
+++ b/crates/openhuman-core/src/cron/client_testing.rs
@@ -0,0 +1,53 @@
+//! Reading a scope's cron store straight through the module, for tests that
+//! stage a backend and check what an importer or another writer left in it.
+
+ use super::*;
+ use crate::storage::{Scope, StorageBackend};
+ use std::sync::Arc;
+ use tinyflows_bus::schedule::types::CronRun;
+
+ fn run<T: Send + 'static>(
+ backend: &Arc<dyn StorageBackend>,
+ scope: &Scope,
+ operation: StoreOperation,
+ ) -> Result<T>
+ where
+ T: DeserializeOwned,
+ {
+ let config = Config::default();
+ let scope = DocScope::on_backend(&config, Arc::clone(backend), scope.clone());
+ crate::storage::block_on_anyhow(async move { store_in(&config, &scope, operation).await })
+ }
+
+ pub(crate) fn list_jobs(backend: &Arc<dyn StorageBackend>, scope: &Scope) -> Result<Vec<CronJob>> {
+ run(backend, scope, StoreOperation::List)
+ }
+
+ pub(crate) fn get_job(
+ backend: &Arc<dyn StorageBackend>,
+ scope: &Scope,
+ job_id: &str,
+ ) -> Result<CronJob> {
+ run(
+ backend,
+ scope,
+ StoreOperation::Get {
+ job_id: job_id.to_string(),
+ },
+ )
+ }
+
+ pub(crate) fn list_runs(
+ backend: &Arc<dyn StorageBackend>,
+ scope: &Scope,
+ job_id: &str,
+ ) -> Result<Vec<CronRun>> {
+ run(
+ backend,
+ scope,
+ StoreOperation::ListRuns {
+ job_id: job_id.to_string(),
+ limit: 50,
+ },
+ )
+ }
diff --git a/crates/openhuman-core/src/modules/tinyflows.rs b/crates/openhuman-core/src/modules/tinyflows.rs
index f9a7a326dd..c15222ffe8 100644
--- a/crates/openhuman-core/src/modules/tinyflows.rs
+++ b/crates/openhuman-core/src/modules/tinyflows.rs
@@ -69,7 +69,7 @@ mod imp {
#[cfg(test)]
{
let _ = config;
- fixture::attach().await
+ super::fixture::attach().await
}
#[cfg(not(test))]
{
@@ -153,33 +153,12 @@ mod imp {
.await;
});
}
-
- /// The tinyflows module linked into the test binary.
- #[cfg(test)]
- pub(crate) mod fixture {
- use crate::config::schema::ModuleSourceMode;
- use crate::config::Config;
- use crate::modules::{linked::register_linked, ops};
- use tokio::sync::OnceCell;
-
- static ATTACHED: OnceCell<Result<(), String>> = OnceCell::const_new();
-
- /// Attach the linked module to the process-wide module host, once.
- pub(crate) async fn attach() -> Result<(), String> {
- ATTACHED
- .get_or_init(|| async {
- register_linked(super::MODULE_ID, tinyflows_module::linked_module);
- let mut config = Config::default();
- config.modules.allow_download = false;
- config.modules.source = ModuleSourceMode::Linked;
- ops::ensure_loaded(&config, super::MODULE_ID).await
- })
- .await
- .clone()
- }
- }
}
+#[cfg(all(test, feature = "modules"))]
+#[path = "tinyflows_fixture.rs"]
+mod fixture;
+
#[cfg(feature = "modules")]
pub(crate) use imp::{proxy, run_proxy, serve, unserve};
diff --git a/crates/openhuman-core/src/modules/tinyflows_fixture.rs b/crates/openhuman-core/src/modules/tinyflows_fixture.rs
new file mode 100644
index 0000000000..f1c2a78ae7
--- /dev/null
+++ b/crates/openhuman-core/src/modules/tinyflows_fixture.rs
@@ -0,0 +1,23 @@
+//! The tinyflows module linked into the test binary: the `static-link` build of
+//! `tinyflows-module`, attached once to the process-wide module host.
+
+use crate::config::schema::ModuleSourceMode;
+use crate::config::Config;
+use crate::modules::{linked::register_linked, ops};
+use tokio::sync::OnceCell;
+
+static ATTACHED: OnceCell<Result<(), String>> = OnceCell::const_new();
+
+/// Attach the linked module to the process-wide module host, once.
+pub(crate) async fn attach() -> Result<(), String> {
+ ATTACHED
+ .get_or_init(|| async {
+ register_linked(super::MODULE_ID, tinyflows_module::linked_module);
+ let mut config = Config::default();
+ config.modules.allow_download = false;
+ config.modules.source = ModuleSourceMode::Linked;
+ ops::ensure_loaded(&config, super::MODULE_ID).await
+ })
+ .await
+ .clone()
+}