-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add automation run history UI #4580
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d105df4
c60e80a
f7db96c
125cf1f
45a61de
3f33022
9308d7a
20eb5f5
d133298
9d7dd6a
48762c5
b51f251
cd85b08
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,7 @@ use ironclaw_host_api::{ | |
| }; | ||
| use ironclaw_triggers::{ | ||
| TriggerCompletionPolicy, TriggerError, TriggerId, TriggerRecord, TriggerRepository, | ||
| TriggerSchedule, TriggerSourceKind, TriggerState, | ||
| TriggerRunRecord, TriggerSchedule, TriggerSourceKind, TriggerState, | ||
| }; | ||
| use serde::Deserialize; | ||
| use serde_json::{Value, json}; | ||
|
|
@@ -24,7 +24,9 @@ use super::{ | |
| first_party_capability_manifest, input_error, resource_profile, | ||
| }; | ||
|
|
||
| const TRIGGER_LIST_LIMIT: usize = 100; | ||
| const TRIGGER_LIST_MAX_LIMIT: usize = 100; | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit — TRIGGER_LIST_MAX_LIMIT used as both default and max while sibling pair uses separate DEFAULT/MAX. PR introduces TRIGGER_RUN_HISTORY_DEFAULT_LIMIT + TRIGGER_RUN_HISTORY_MAX_LIMIT paired naming. Adjacent TRIGGER_LIST_MAX_LIMIT (renamed from TRIGGER_LIST_LIMIT) remains a single constant doubling as both default and max ( Fix: Either add TRIGGER_LIST_DEFAULT_LIMIT separate from TRIGGER_LIST_MAX_LIMIT, or rename the new pair to TRIGGER_RUN_HISTORY_LIMIT (single constant). At minimum: comment noting the dual role. |
||
| const TRIGGER_RUN_HISTORY_DEFAULT_LIMIT: usize = 25; | ||
|
henrypark133 marked this conversation as resolved.
|
||
| const TRIGGER_RUN_HISTORY_MAX_LIMIT: usize = 100; | ||
|
|
||
| pub const TRIGGER_CREATE_CAPABILITY_ID: &str = "builtin.trigger_create"; | ||
| pub const TRIGGER_LIST_CAPABILITY_ID: &str = "builtin.trigger_list"; | ||
|
|
@@ -205,6 +207,7 @@ struct TriggerRemoveInput { | |
| #[derive(Deserialize)] | ||
| struct TriggerListInput { | ||
| limit: Option<usize>, | ||
| run_limit: Option<usize>, | ||
| } | ||
|
|
||
| async fn create_trigger( | ||
|
|
@@ -256,7 +259,7 @@ async fn create_trigger( | |
| return Err(hook_error); | ||
| } | ||
| Ok(json!({ | ||
| "trigger": trigger_output(&record), | ||
| "trigger": trigger_output(&record, &[]), | ||
| })) | ||
| } | ||
|
|
||
|
|
@@ -268,8 +271,12 @@ async fn list_triggers( | |
| let input: TriggerListInput = serde_json::from_value(input).map_err(|_| input_error())?; | ||
| let limit = input | ||
| .limit | ||
| .unwrap_or(TRIGGER_LIST_LIMIT) | ||
| .min(TRIGGER_LIST_LIMIT); | ||
| .unwrap_or(TRIGGER_LIST_MAX_LIMIT) | ||
| .min(TRIGGER_LIST_MAX_LIMIT); | ||
| let run_limit = input | ||
| .run_limit | ||
|
henrypark133 marked this conversation as resolved.
|
||
| .unwrap_or(TRIGGER_RUN_HISTORY_DEFAULT_LIMIT) | ||
| .min(TRIGGER_RUN_HISTORY_MAX_LIMIT); | ||
| let records = repository | ||
| .list_scoped_triggers( | ||
| scope.tenant_id.clone(), | ||
|
|
@@ -279,11 +286,25 @@ async fn list_triggers( | |
| limit, | ||
| ) | ||
| .await | ||
| .map_err(|error| trigger_repository_error("list_scoped_triggers", error))? | ||
| .map_err(|error| trigger_repository_error("list_scoped_triggers", error))?; | ||
| let trigger_ids = records | ||
| .iter() | ||
| .map(|record| record.trigger_id) | ||
| .collect::<Vec<_>>(); | ||
| let mut runs_by_trigger = repository | ||
| .list_trigger_run_history_batch(scope.tenant_id.clone(), &trigger_ids, run_limit) | ||
|
henrypark133 marked this conversation as resolved.
|
||
| .await | ||
| .map_err(|error| trigger_repository_error("list_trigger_run_history_batch", error))?; | ||
| let output = records | ||
| .into_iter() | ||
| .map(|record| trigger_output(&record)) | ||
| .map(|record| { | ||
| let runs = runs_by_trigger | ||
| .remove(&record.trigger_id) | ||
| .unwrap_or_default(); | ||
| trigger_output(&record, &runs) | ||
| }) | ||
| .collect::<Vec<_>>(); | ||
| Ok(json!({ "triggers": records })) | ||
| Ok(json!({ "triggers": output })) | ||
| } | ||
|
|
||
| async fn remove_trigger( | ||
|
|
@@ -309,7 +330,7 @@ async fn remove_trigger( | |
| })) | ||
| } | ||
|
|
||
| fn trigger_output(record: &TriggerRecord) -> Value { | ||
| fn trigger_output(record: &TriggerRecord, recent_runs: &[TriggerRunRecord]) -> Value { | ||
| json!({ | ||
| "trigger_id": record.trigger_id.to_string(), | ||
| "agent_id": record.agent_id.as_ref().map(|id| id.as_str()), | ||
|
|
@@ -322,11 +343,23 @@ fn trigger_output(record: &TriggerRecord) -> Value { | |
| "next_run_at": record.next_run_at, | ||
| "last_run_at": record.last_run_at, | ||
| "last_status": record.last_status, | ||
| "recent_runs": recent_runs.iter().map(trigger_run_output).collect::<Vec<_>>(), | ||
| "is_active": record.has_active_fire(), | ||
| "created_at": record.created_at, | ||
| }) | ||
| } | ||
|
|
||
| fn trigger_run_output(run: &TriggerRunRecord) -> Value { | ||
| json!({ | ||
| "fire_slot": run.fire_slot, | ||
| "run_id": run.run_id.as_ref().map(ToString::to_string), | ||
| "thread_id": run.thread_id.as_str(), | ||
| "status": run.status, | ||
| "submitted_at": run.submitted_at, | ||
| "completed_at": run.completed_at, | ||
| }) | ||
| } | ||
|
|
||
| fn trigger_remove_output(record: &TriggerRecord) -> Value { | ||
| json!({ | ||
| "trigger_id": record.trigger_id.to_string(), | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.