mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-03 00:47:53 +00:00
Query pending TTS job count (public use)
This commit is contained in:
1 parent
820417ac0f
commit
101d145709
5 files changed
+57
-1
No files matched your search
@@ -1,3 +1,4 @@
|
||||
// TODO: Use macros to generate everything, or better, use a library (or stdlib) that does these.
|
||||
|
||||
/// MySQL stores non-nullable booleans as i8.
|
||||
pub fn i8_to_bool(value: i8) -> bool {
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
pub mod boolean_converters;
|
||||
pub mod boolean_converters;
|
||||
pub mod numeric_converters;
|
||||
@@ -0,0 +1,29 @@
|
||||
// TODO: Use macros to generate everything, or better, use a library (or stdlib) that does these.
|
||||
|
||||
pub fn try_i64_to_u64_or_min(value: i64) -> u64 {
|
||||
if value < 0 {
|
||||
u64::MIN
|
||||
} else {
|
||||
value as u64
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::helpers::numeric_converters::try_i64_to_u64_or_min;
|
||||
|
||||
#[test]
|
||||
fn test_try_i64_to_u64_or_min() {
|
||||
// Positive
|
||||
assert_eq!(try_i64_to_u64_or_min(1i64), 1u64);
|
||||
assert_eq!(try_i64_to_u64_or_min(1000i64), 1000u64);
|
||||
assert_eq!(try_i64_to_u64_or_min(9999999i64), 9999999u64);
|
||||
assert_eq!(try_i64_to_u64_or_min(i64::MAX), 9223372036854775807u64);
|
||||
// Zero
|
||||
assert_eq!(try_i64_to_u64_or_min(0i64), 0u64);
|
||||
// Negative
|
||||
assert_eq!(try_i64_to_u64_or_min(-1i64), 0u64);
|
||||
assert_eq!(try_i64_to_u64_or_min(-1000i64), 0u64);
|
||||
assert_eq!(try_i64_to_u64_or_min(i64::MIN), 0u64);
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
use container_common::anyhow_result::AnyhowResult;
|
||||
use crate::helpers::numeric_converters::try_i64_to_u64_or_min;
|
||||
use sqlx::MySqlPool;
|
||||
|
||||
pub async fn get_pending_tts_inference_job_count(
|
||||
pool: &MySqlPool,
|
||||
) -> AnyhowResult<u64> {
|
||||
let result : CountResult = sqlx::query_as!(
|
||||
CountResult,
|
||||
r#"
|
||||
SELECT count(*) as record_count
|
||||
FROM tts_inference_jobs
|
||||
WHERE status IN ("pending", "started", "attempt_failed")
|
||||
"#,
|
||||
)
|
||||
.fetch_one(pool)
|
||||
.await?;
|
||||
|
||||
Ok(try_i64_to_u64_or_min(result.record_count))
|
||||
}
|
||||
|
||||
struct CountResult {
|
||||
record_count: i64,
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
pub mod _keys;
|
||||
pub mod get_pending_tts_inference_job_count;
|
||||
pub mod insert_tts_inference_job;
|
||||
pub mod kill_tts_inference_jobs;
|
||||
pub mod list_available_tts_inference_jobs;
|
||||
|
||||
Reference in new issue
Block a user