Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 17 additions & 21 deletions crates/goose-server/src/routes/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,26 +231,17 @@ async fn run_now_handler(
.await
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;

let recipe_display_name = match scheduler.list_scheduled_jobs().await {
Ok(jobs) => jobs
.into_iter()
.find(|job| job.id == id)
.and_then(|job| {
std::path::Path::new(&job.source)
let (recipe_display_name, recipe_version_opt) = match scheduler.list_scheduled_jobs().await {
Ok(jobs) => {
if let Some(job) = jobs.into_iter().find(|job| job.id == id) {
let recipe_display_name = std::path::Path::new(&job.source)
.file_name()
.and_then(|name| name.to_str())
.map(|s| s.to_string())
})
.unwrap_or_else(|| id.clone()),
Err(_) => id.clone(),
};
.unwrap_or_else(|| id.clone());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we just use the name of recipe, rather than basing something on the filename?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was contemplating it. but we do use the filename as a more unique indicator. I can have 7 recipes with the same title, but filenames will be unique

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont want to be difficult here, but the variable is called recipe_display_name, so showing the name of the recipe seems kinda reasonable. the plan is to merge recipes and scheduler either way and do away with the extra naming layers we have everywhere, fwiw

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah good to know. Can we just leave this until then to avoid redundant work?


let recipe_version = match scheduler.list_scheduled_jobs().await {
Ok(jobs) => jobs
.into_iter()
.find(|job| job.id == id)
.and_then(|job| {
std::fs::read_to_string(&job.source)
let recipe_version_opt = tokio::fs::read_to_string(&job.source)
.await
.ok()
.and_then(|content| {
goose::recipe::template_recipe::parse_recipe_content(
Expand All @@ -263,16 +254,21 @@ async fn run_now_handler(
)
.ok()
.map(|(r, _)| r.version)
})
})
.unwrap_or_else(|| "unknown".to_string()),
Err(_) => "unknown".to_string(),
});

(recipe_display_name, recipe_version_opt)
} else {
(id.clone(), None)
}
}
Err(_) => (id.clone(), None),
};

let recipe_version_tag = recipe_version_opt.as_deref().unwrap_or("");
tracing::info!(
counter.goose.recipe_runs = 1,
recipe_name = %recipe_display_name,
recipe_version = %recipe_version,
recipe_version = %recipe_version_tag,
session_type = "schedule",
interface = "server",
"Recipe execution started"
Expand Down
Loading