mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-16 23:03:06 +00:00
cli
This commit is contained in:
1 parent
53f34061b6
commit
b06ab8ae76
3 files changed
+72
No files matched your search
@@ -6,6 +6,9 @@ use super::subcommands;
|
||||
|
||||
#[derive(Subcommand)]
|
||||
pub enum Seedance2proCommand {
|
||||
/// Scan all jobs and print a histogram of failure reasons
|
||||
Failedjobhistogram,
|
||||
|
||||
/// Find a job by its order ID across all pages
|
||||
Findjob(subcommands::findjob::FindjobArgs),
|
||||
}
|
||||
@@ -17,6 +20,7 @@ pub async fn run(command: Seedance2proCommand) -> anyhow::Result<()> {
|
||||
let state = Seedance2ProState { cookies };
|
||||
|
||||
match command {
|
||||
Seedance2proCommand::Failedjobhistogram => subcommands::failedjobhistogram::run(&state).await,
|
||||
Seedance2proCommand::Findjob(args) => subcommands::findjob::run(&state, args).await,
|
||||
}
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use anyhow::anyhow;
|
||||
use log::info;
|
||||
use seedance2pro::creds::seedance2pro_session::Seedance2ProSession;
|
||||
use seedance2pro::requests::poll_orders::poll_orders::{poll_orders, PollOrdersArgs, TaskStatus};
|
||||
|
||||
use super::super::state::Seedance2ProState;
|
||||
|
||||
pub async fn run(state: &Seedance2ProState) -> anyhow::Result<()> {
|
||||
let session = Seedance2ProSession::from_cookies_string(state.cookies.clone());
|
||||
|
||||
let mut cursor: Option<u64> = None;
|
||||
let mut page = 0usize;
|
||||
let mut total_orders = 0usize;
|
||||
let mut failed_count = 0usize;
|
||||
let mut histogram: BTreeMap<String, usize> = BTreeMap::new();
|
||||
|
||||
loop {
|
||||
page += 1;
|
||||
info!("Fetching page {} (cursor: {:?})...", page, cursor);
|
||||
|
||||
let result = poll_orders(PollOrdersArgs {
|
||||
session: &session,
|
||||
cursor,
|
||||
}).await
|
||||
.map_err(|err| anyhow!("Error polling orders on page {}: {:?}", page, err))?;
|
||||
|
||||
let page_count = result.orders.len();
|
||||
total_orders += page_count;
|
||||
|
||||
for order in &result.orders {
|
||||
if order.task_status == TaskStatus::Failed {
|
||||
failed_count += 1;
|
||||
let reason = order.fail_reason.as_deref().unwrap_or("(no reason)");
|
||||
*histogram.entry(reason.to_string()).or_insert(0) += 1;
|
||||
}
|
||||
}
|
||||
|
||||
info!("Page {}: {} orders ({} failed so far).", page, page_count, failed_count);
|
||||
|
||||
cursor = result.next_cursor;
|
||||
if cursor.is_none() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
println!("\nScanned {} orders across {} pages.", total_orders, page);
|
||||
println!("Failed: {}\n", failed_count);
|
||||
|
||||
if histogram.is_empty() {
|
||||
println!("No failed jobs found.");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// Sort by count descending.
|
||||
let mut sorted: Vec<(&String, &usize)> = histogram.iter().collect();
|
||||
sorted.sort_by(|a, b| b.1.cmp(a.1));
|
||||
|
||||
println!("{:<6} {}", "Count", "Failure Reason");
|
||||
println!("{:<6} {}", "-----", "--------------");
|
||||
for (reason, count) in &sorted {
|
||||
println!("{:<6} {}", count, reason);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -1 +1,2 @@
|
||||
pub mod failedjobhistogram;
|
||||
pub mod findjob;
|
||||
Reference in new issue
Block a user