Skip to content

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

refactor(cron): move scheduler config and loop slot into manual_run

Steven Enamakel2e745fc35e43
diff --git a/crates/openhuman-core/src/cron/scheduler.rs b/crates/openhuman-core/src/cron/scheduler.rs
index 80ce5563bc..67464f58d2 100644
--- a/crates/openhuman-core/src/cron/scheduler.rs
+++ b/crates/openhuman-core/src/cron/scheduler.rs
@@ -47,6 +47,7 @@ use shell_job::*;
pub use delivery::deliver_job;
use crate::config::Config;
+use manual_run::{LoopSlot, MIN_POLL_SECONDS};
use crate::core::bus::BUS;
use crate::core::events::DomainEvent;
use crate::cron::bus_host::{self, Binding, HostRegistration, CLAIM_SCOPE};
@@ -62,16 +63,6 @@ use tinyflows_bus::schedule::types::CronJob;
use tinyflows_bus::schedule::{members, Attempt, StartScheduler, StoreBackend, StoreConfig};
use tokio::time::{self, Duration};
-/// The module's retry settings from the operator's reliability config.
-pub(crate) fn scheduler_config(config: &Config) -> Value {
- json!({
- "poll_secs": config.reliability.scheduler_poll_secs,
- "max_concurrent": config.scheduler.max_concurrent,
- "retries": config.reliability.scheduler_retries,
- "backoff_ms": config.reliability.provider_backoff_ms,
- })
-}
-
pub async fn run(ctx: &crate::core::runtime::DispatchCtx, config: Config) -> Result<()> {
let Some(_slot) = LoopSlot::acquire() else {
tracing::warn!(
@@ -113,10 +104,8 @@ pub async fn run(ctx: &crate::core::runtime::DispatchCtx, config: Config) -> Res
}
-#[cfg(test)]
-#[path = "scheduler_tests.rs"]
-mod scheduler_tests;
-
pub(crate) use dispatcher::{execute_job_now, tick_once, JobDispatcher};
-pub(crate) use live_agents::{run_live_agent_pass, LiveAgentSchedulers};
-pub(crate) use manual_run::{is_running, scheduler_config, try_acquire_run, RunGuard, ALREADY_RUNNING};
+pub use live_agents::run_live_agent_pass;
+pub(crate) use live_agents::LiveAgentSchedulers;
+pub use manual_run::is_running;
+pub(crate) use manual_run::{scheduler_config, try_acquire_run, RunGuard, ALREADY_RUNNING};
diff --git a/crates/openhuman-core/src/cron/scheduler/manual_run.rs b/crates/openhuman-core/src/cron/scheduler/manual_run.rs
index a7e6ae8721..3ca7582e1e 100644
--- a/crates/openhuman-core/src/cron/scheduler/manual_run.rs
+++ b/crates/openhuman-core/src/cron/scheduler/manual_run.rs
@@ -1,6 +1,6 @@
use super::*;
-const MIN_POLL_SECONDS: u64 = 5;
+pub(super) const MIN_POLL_SECONDS: u64 = 5;
/// What the module answers when another run of the job holds its claim.
pub(crate) const ALREADY_RUNNING: &str = "job is already running";
@@ -10,10 +10,10 @@ static LOOP_RUNNING: AtomicBool = AtomicBool::new(false);
/// The poll-loop slot: one loop per process, or two would each see the same
/// due rows. Released when dropped.
-struct LoopSlot;
+pub(super) struct LoopSlot;
impl LoopSlot {
- fn acquire() -> Option<Self> {
+ pub(super) fn acquire() -> Option<Self> {
LOOP_RUNNING
.compare_exchange(false, true, Ordering::SeqCst, Ordering::SeqCst)
.ok()