feat(enhance): discard, tests against a mock ComfyUI, docs (#192)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3a21761cfe
commit
97d9301a71
10 files changed
+1165
-48
No files matched your search
+27
-18
@@ -13,9 +13,7 @@ use std::time::{Duration, Instant};
|
||||
use log::{info, warn};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::comfy::{
|
||||
ApproveError, ComfyClient, ComfyError, HistoryEntry, Staged, SubmitError,
|
||||
};
|
||||
use super::comfy::{ApproveError, ComfyClient, ComfyError, HistoryEntry, Staged, SubmitError};
|
||||
use super::config::{EnhanceConfig, Loaded, PromptMode};
|
||||
use super::path_map::PathMap;
|
||||
use super::template::Template;
|
||||
@@ -35,8 +33,7 @@ const JOB_RETENTION_SECS: i64 = 14 * 24 * 3600;
|
||||
pub const JOBS_PER_PHOTO: i64 = 20;
|
||||
|
||||
pub const MSG_UNAVAILABLE: &str = "ComfyUI isn't running";
|
||||
pub const MSG_EXPIRED: &str =
|
||||
"This result expired (ComfyUI was restarted). Run it again.";
|
||||
pub const MSG_EXPIRED: &str = "This result expired (ComfyUI was restarted). Run it again.";
|
||||
pub const MSG_DISABLED: &str = "Enhance isn't configured";
|
||||
|
||||
/// A library file a request names.
|
||||
@@ -247,10 +244,12 @@ impl EnhanceService {
|
||||
}
|
||||
|
||||
pub fn default_template(&self) -> Option<&str> {
|
||||
let wanted = self.config.default_name()?;
|
||||
self.template(wanted)
|
||||
self.config
|
||||
.default_template
|
||||
.as_deref()
|
||||
.and_then(|w| self.template(w))
|
||||
.or_else(|| self.templates.first())
|
||||
.map(|t| t.cfg.name.as_str())
|
||||
.or_else(|| self.templates.first().map(|t| t.cfg.name.as_str()))
|
||||
}
|
||||
|
||||
/// Cached `GET /system_stats` probe.
|
||||
@@ -315,12 +314,9 @@ impl EnhanceService {
|
||||
None => None,
|
||||
};
|
||||
let filled = template
|
||||
.fill(
|
||||
&source,
|
||||
prompt,
|
||||
reference_path.as_deref(),
|
||||
&mut || rand::random::<u64>() >> 12,
|
||||
)
|
||||
.fill(&source, prompt, reference_path.as_deref(), &mut || {
|
||||
rand::random::<u64>() >> 12
|
||||
})
|
||||
.map_err(|e| EnhanceError::BadRequest(e.0))?;
|
||||
|
||||
if !self.probe_now().await {
|
||||
@@ -329,7 +325,10 @@ impl EnhanceService {
|
||||
let prompt_id = match client.submit(&filled.prompt).await {
|
||||
Ok(id) => id,
|
||||
Err(SubmitError::Comfy(e)) => return Err(comfy_err(e)),
|
||||
Err(SubmitError::Rejected { message, node_errors }) => {
|
||||
Err(SubmitError::Rejected {
|
||||
message,
|
||||
node_errors,
|
||||
}) => {
|
||||
// A reference-less run of a template that wants one fails
|
||||
// validation on the dropped node's consumers.
|
||||
return Err(if filled.dropped_reference && node_errors {
|
||||
@@ -481,7 +480,11 @@ impl EnhanceService {
|
||||
for job in active {
|
||||
self.unreachable_since.lock().unwrap().remove(&job.id);
|
||||
if let Some((running, ahead)) = queue.position_of(&job.comfy_prompt_id) {
|
||||
let status = if running { STATUS_RUNNING } else { STATUS_QUEUED };
|
||||
let status = if running {
|
||||
STATUS_RUNNING
|
||||
} else {
|
||||
STATUS_QUEUED
|
||||
};
|
||||
let mut u = JobUpdate::status(status);
|
||||
u.queue_position = Some(ahead as i32);
|
||||
if job.status != status || job.queue_position != u.queue_position {
|
||||
@@ -501,7 +504,9 @@ impl EnhanceService {
|
||||
u.error = Some(MSG_EXPIRED.to_string());
|
||||
self.update_job(&job.id, &u);
|
||||
}
|
||||
Err(ComfyError::Unreachable(_)) => self.note_unreachable(std::slice::from_ref(&job)),
|
||||
Err(ComfyError::Unreachable(_)) => {
|
||||
self.note_unreachable(std::slice::from_ref(&job))
|
||||
}
|
||||
Err(e) => warn!("enhance: /history for job {} failed: {e}", job.id),
|
||||
}
|
||||
}
|
||||
@@ -527,7 +532,11 @@ impl EnhanceService {
|
||||
let mut u = JobUpdate::status(STATUS_READY);
|
||||
u.pending = serde_json::to_string(&entry.staged).ok();
|
||||
self.update_job(&job.id, &u);
|
||||
info!("enhance: job {} ready ({} result(s))", job.id, entry.staged.len());
|
||||
info!(
|
||||
"enhance: job {} ready ({} result(s))",
|
||||
job.id,
|
||||
entry.staged.len()
|
||||
);
|
||||
}
|
||||
|
||||
fn note_unreachable(&self, jobs: &[EnhanceJobRow]) {
|
||||
|
||||
Reference in new issue
Block a user