Skip to content

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

feat(cron): add persistent store for scheduled jobs

Steven Enamakelec713bea1916
diff --git a/crates/openhuman-core/src/cron/mod.rs b/crates/openhuman-core/src/cron/mod.rs
index 2a823f603a..e81c50c100 100644
--- a/crates/openhuman-core/src/cron/mod.rs
+++ b/crates/openhuman-core/src/cron/mod.rs
@@ -10,7 +10,9 @@
pub mod scheduler_gate;
pub mod bus;
+pub mod job_builder;
pub mod ops;
+pub mod origin;
mod schemas;
pub mod seed;
mod store;
@@ -30,9 +32,9 @@ pub use schemas::{
};
#[allow(unused_imports)]
pub use store::{
- add_agent_job, add_agent_job_with_definition, add_flow_schedule_job, add_job, add_shell_job,
+ add_agent_job, add_agent_job_from_spec, add_agent_job_with_definition, add_flow_schedule_job, add_job, add_shell_job,
clear_all_jobs, dedup_named_jobs, delete_queued_runs, due_jobs, find_flow_schedule_job,
- get_job, list_jobs, list_runs, record_last_run, record_run, remove_job, reschedule_after_run,
+ get_job, list_jobs, list_runs, record_last_run, record_run, record_run_with_delivery, remove_job, reschedule_after_run,
update_job,
};
#[allow(unused_imports)]
@@ -41,5 +43,8 @@ pub use tinyflows_schedule::schedule::{
validate_agent_schedule, validate_schedule, TooFrequent, MIN_AGENT_JOB_INTERVAL,
};
pub use tinyflows_schedule::types::{
- ActiveHours, CronJob, CronJobPatch, CronRun, DeliveryConfig, JobType, Schedule, SessionTarget,
+ ActiveHours, CronJob, CronJobPatch, CronRun, DeliveryConfig, DeliveryStatus, JobOrigin,
+ JobType, Schedule, SessionTarget,
};
+pub use tinyflows_schedule::types::delivery_mode;
+pub use tinyflows_sqlite::schedule::AgentJobSpec;
diff --git a/crates/openhuman-core/src/cron/store.rs b/crates/openhuman-core/src/cron/store.rs
index 90526a0c84..1743be82c2 100644
--- a/crates/openhuman-core/src/cron/store.rs
+++ b/crates/openhuman-core/src/cron/store.rs
@@ -9,7 +9,8 @@ use crate::config::Config;
use anyhow::Result;
use chrono::{DateTime, Utc};
use tinyflows_schedule::{CronJob, CronJobPatch, CronRun, DeliveryConfig, Schedule, SessionTarget};
-use tinyflows_sqlite::schedule::{self as upstream, CronStoreOptions};
+use tinyflows_schedule::DeliveryStatus;
+use tinyflows_sqlite::schedule::{self as upstream, AgentJobSpec, CronStoreOptions};
/// Builds the store options from the host config: `<workspace>/cron/jobs.db`,
/// `cron.max_run_history`, `scheduler.max_tasks`.
@@ -86,6 +87,11 @@ pub fn add_agent_job_with_definition(
)
}
+/// Adds an agent job described by `spec`, including its origin conversation.
+pub fn add_agent_job_from_spec(config: &Config, spec: AgentJobSpec) -> Result<CronJob> {
+ upstream::add_agent_job_from_spec(&opts(config), spec)
+}
+
/// Registers (idempotently) the cron job that fires a flow's `schedule`
/// trigger; see `tinyflows_sqlite::schedule::add_flow_schedule_job`.
pub fn add_flow_schedule_job(
@@ -171,6 +177,30 @@ pub fn record_run(
)
}
+/// [`record_run`] plus the outcome of delivering the run's result.
+#[allow(clippy::too_many_arguments)]
+pub fn record_run_with_delivery(
+ config: &Config,
+ job_id: &str,
+ started_at: DateTime<Utc>,
+ finished_at: DateTime<Utc>,
+ status: &str,
+ output: Option<&str>,
+ duration_ms: i64,
+ delivery_status: Option<DeliveryStatus>,
+) -> Result<()> {
+ upstream::record_run_with_delivery(
+ &opts(config),
+ job_id,
+ started_at,
+ finished_at,
+ status,
+ output,
+ duration_ms,
+ delivery_status,
+ )
+}
+
/// Removes "queued" placeholder rows so only the real result row remains.
pub fn delete_queued_runs(config: &Config, job_id: &str) -> Result<usize> {
upstream::delete_queued_runs(&opts(config), job_id)
diff --git a/vendor/tinyagents b/vendor/tinyagents
index 3fcdbe213b..80ca2b39a7 160000
--- a/vendor/tinyagents
+++ b/vendor/tinyagents
@@ -1 +1 @@
-Subproject commit 3fcdbe213beec1569d0fc23153ab084683f241f4
+Subproject commit 80ca2b39a70aef699dbe208e91eec030a43e36f1