mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-04 17:38:10 +00:00
port storyteller-web get w2l inference job status
This commit is contained in:
1 parent
0e39999097
commit
910caa1000
3 files changed
+81
-45
No files matched your search
+67
@@ -0,0 +1,67 @@
|
||||
use anyhow::anyhow;
|
||||
use chrono::{DateTime, Utc};
|
||||
use sqlx::MySqlPool;
|
||||
use errors::AnyhowResult;
|
||||
|
||||
pub struct W2lInferenceJobStatusRecord {
|
||||
pub job_token: String,
|
||||
|
||||
pub status: String,
|
||||
pub attempt_count: i32,
|
||||
pub maybe_result_token: Option<String>,
|
||||
pub maybe_public_bucket_video_path: Option<String>,
|
||||
|
||||
pub maybe_w2l_template_token: Option<String>,
|
||||
pub w2l_template_type: String,
|
||||
|
||||
pub title: String,
|
||||
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub updated_at: DateTime<Utc>,
|
||||
}
|
||||
|
||||
pub async fn get_w2l_inference_job_status(
|
||||
job_token: &str,
|
||||
mysql_pool: &MySqlPool,
|
||||
) -> AnyhowResult<Option<W2lInferenceJobStatusRecord>> {
|
||||
// NB: Lookup failure is Err(RowNotFound).
|
||||
// NB: Since this is publicly exposed, we don't query sensitive data.
|
||||
let maybe_status = sqlx::query_as!(
|
||||
W2lInferenceJobStatusRecord,
|
||||
r#"
|
||||
SELECT
|
||||
jobs.token as job_token,
|
||||
|
||||
jobs.status,
|
||||
jobs.attempt_count,
|
||||
jobs.on_success_result_token as maybe_result_token,
|
||||
results.public_bucket_video_path as maybe_public_bucket_video_path,
|
||||
|
||||
jobs.maybe_w2l_template_token,
|
||||
w2l.template_type as w2l_template_type,
|
||||
w2l.title,
|
||||
|
||||
jobs.created_at,
|
||||
jobs.updated_at
|
||||
|
||||
FROM w2l_inference_jobs as jobs
|
||||
JOIN w2l_templates as w2l
|
||||
ON w2l.token = jobs.maybe_w2l_template_token
|
||||
LEFT OUTER JOIN w2l_results as results
|
||||
ON jobs.on_success_result_token = results.token
|
||||
|
||||
WHERE jobs.token = ?
|
||||
"#,
|
||||
job_token
|
||||
)
|
||||
.fetch_one(mysql_pool)
|
||||
.await;
|
||||
|
||||
match maybe_status {
|
||||
Ok(record) => Ok(Some(record)),
|
||||
Err(err) => match err {
|
||||
sqlx::Error::RowNotFound => Ok(None),
|
||||
_ => Err(anyhow!("w2l template query error: {:?}", err)),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,2 +1,3 @@
|
||||
pub mod get_w2l_inference_job_status;
|
||||
pub mod insert_w2l_inference_job;
|
||||
pub mod w2l_inference_job_queries; // TODO: The "job queries" were moved here; now break them down into several files.
|
||||
+13
-45
@@ -10,6 +10,7 @@ use chrono::{DateTime, Utc};
|
||||
use crate::AnyhowResult;
|
||||
use crate::http_server::web_utils::response_error_helpers::to_simple_json_error;
|
||||
use crate::server_state::ServerState;
|
||||
use database_queries::queries::w2l::w2l_inference_jobs::get_w2l_inference_job_status::get_w2l_inference_job_status;
|
||||
use log::{info, warn, log};
|
||||
use r2d2_redis::redis::Commands;
|
||||
use redis_common::redis_keys::RedisKeys;
|
||||
@@ -107,53 +108,20 @@ pub async fn get_w2l_inference_job_status_handler(
|
||||
path: Path<GetW2lInferenceStatusPathInfo>,
|
||||
server_state: web::Data<Arc<ServerState>>) -> Result<HttpResponse, GetW2lInferenceStatusError>
|
||||
{
|
||||
// NB: Lookup failure is Err(RowNotFound).
|
||||
// NB: Since this is publicly exposed, we don't query sensitive data.
|
||||
let maybe_status = sqlx::query_as!(
|
||||
W2lInferenceJobStatusRecord,
|
||||
r#"
|
||||
SELECT
|
||||
jobs.token as job_token,
|
||||
let maybe_status = get_w2l_inference_job_status(
|
||||
&path.token,
|
||||
&server_state.mysql_pool
|
||||
).await;
|
||||
|
||||
jobs.status,
|
||||
jobs.attempt_count,
|
||||
jobs.on_success_result_token as maybe_result_token,
|
||||
results.public_bucket_video_path as maybe_public_bucket_video_path,
|
||||
|
||||
jobs.maybe_w2l_template_token,
|
||||
w2l.template_type as w2l_template_type,
|
||||
w2l.title,
|
||||
|
||||
jobs.created_at,
|
||||
jobs.updated_at
|
||||
|
||||
FROM w2l_inference_jobs as jobs
|
||||
JOIN w2l_templates as w2l
|
||||
ON w2l.token = jobs.maybe_w2l_template_token
|
||||
LEFT OUTER JOIN w2l_results as results
|
||||
ON jobs.on_success_result_token = results.token
|
||||
|
||||
WHERE jobs.token = ?
|
||||
"#,
|
||||
&path.token
|
||||
)
|
||||
.fetch_one(&server_state.mysql_pool)
|
||||
.await; // TODO: This will return error if it doesn't exist
|
||||
|
||||
let record : W2lInferenceJobStatusRecord = match maybe_status {
|
||||
Ok(record) => record,
|
||||
Err(err) => {
|
||||
match err {
|
||||
sqlx::Error::RowNotFound => {
|
||||
return Err(GetW2lInferenceStatusError::ServerError);
|
||||
},
|
||||
_ => {
|
||||
warn!("w2l template query error: {:?}", err);
|
||||
return Err(GetW2lInferenceStatusError::ServerError);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
let record = maybe_status
|
||||
.map_err(|err| {
|
||||
warn!("w2l template query error: {:?}", err);
|
||||
GetW2lInferenceStatusError::ServerError
|
||||
})?
|
||||
.ok_or_else(|| {
|
||||
GetW2lInferenceStatusError::ServerError // TODO: Not found
|
||||
})?;
|
||||
|
||||
let mut redis = server_state.redis_pool
|
||||
.get()
|
||||
|
||||
Reference in new issue
Block a user