Platform Tool for Scheduler: Allow Goose to Manage Its Own Schedule (#2944)
This commit is contained in:
@@ -29,7 +29,10 @@ pub async fn run() -> Result<()> {
|
||||
.join("schedules.json");
|
||||
|
||||
let scheduler_instance = SchedulerFactory::create(schedule_file_path).await?;
|
||||
app_state.set_scheduler(scheduler_instance).await;
|
||||
app_state.set_scheduler(scheduler_instance.clone()).await;
|
||||
|
||||
// NEW: Provide scheduler access to the agent
|
||||
agent_ref.set_scheduler(scheduler_instance).await;
|
||||
|
||||
let cors = CorsLayer::new()
|
||||
.allow_origin(Any)
|
||||
|
||||
@@ -93,6 +93,8 @@ fn parse_session_name_to_iso(session_name: &str) -> String {
|
||||
request_body = CreateScheduleRequest,
|
||||
responses(
|
||||
(status = 200, description = "Scheduled job created successfully", body = ScheduledJob),
|
||||
(status = 400, description = "Invalid cron expression or recipe file"),
|
||||
(status = 409, description = "Job ID already exists"),
|
||||
(status = 500, description = "Internal server error")
|
||||
),
|
||||
tag = "schedule"
|
||||
@@ -128,7 +130,13 @@ async fn create_schedule(
|
||||
.await
|
||||
.map_err(|e| {
|
||||
eprintln!("Error creating schedule: {:?}", e); // Log error
|
||||
StatusCode::INTERNAL_SERVER_ERROR
|
||||
match e {
|
||||
goose::scheduler::SchedulerError::JobNotFound(_) => StatusCode::NOT_FOUND,
|
||||
goose::scheduler::SchedulerError::CronParseError(_) => StatusCode::BAD_REQUEST,
|
||||
goose::scheduler::SchedulerError::RecipeLoadError(_) => StatusCode::BAD_REQUEST,
|
||||
goose::scheduler::SchedulerError::JobIdExists(_) => StatusCode::CONFLICT,
|
||||
_ => StatusCode::INTERNAL_SERVER_ERROR,
|
||||
}
|
||||
})?;
|
||||
Ok(Json(job))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user