validation: set status on failure
Some checks are pending
continuous-integration/drone/push Build is running

This commit is contained in:
Quaternions 2024-12-17 20:30:31 -08:00
parent 0dc39121c8
commit 9070d77f41
5 changed files with 33 additions and 23 deletions

View File

@ -173,5 +173,6 @@ impl Context{
Ok(()) Ok(())
} }
action!(action_submission_validated,"validator-validated"); action!(action_submission_validated,"validator-validated");
action!(action_submission_accepted,"validator-failed");
action!(action_submission_released,"releaser-released"); action!(action_submission_released,"releaser-released");
} }

View File

@ -3,6 +3,7 @@
pub enum HandleMessageError{ pub enum HandleMessageError{
Messages(async_nats::jetstream::consumer::pull::MessagesError), Messages(async_nats::jetstream::consumer::pull::MessagesError),
DoubleAck(async_nats::Error), DoubleAck(async_nats::Error),
Json(serde_json::Error),
UnknownSubject(String), UnknownSubject(String),
PublishNew(crate::publish_new::PublishError), PublishNew(crate::publish_new::PublishError),
PublishFix(crate::publish_fix::PublishError), PublishFix(crate::publish_fix::PublishError),
@ -17,6 +18,10 @@ impl std::error::Error for HandleMessageError{}
pub type MessageResult=Result<async_nats::jetstream::Message,async_nats::jetstream::consumer::pull::MessagesError>; pub type MessageResult=Result<async_nats::jetstream::Message,async_nats::jetstream::consumer::pull::MessagesError>;
fn from_slice<'a,T:serde::de::Deserialize<'a>>(slice:&'a [u8])->Result<T,HandleMessageError>{
serde_json::from_slice(slice).map_err(HandleMessageError::Json)
}
pub struct MessageHandler{ pub struct MessageHandler{
publish_new:crate::publish_new::Publisher, publish_new:crate::publish_new::Publisher,
publish_fix:crate::publish_fix::Publisher, publish_fix:crate::publish_fix::Publisher,
@ -39,9 +44,9 @@ impl MessageHandler{
let message=message_result.map_err(HandleMessageError::Messages)?; let message=message_result.map_err(HandleMessageError::Messages)?;
message.double_ack().await.map_err(HandleMessageError::DoubleAck)?; message.double_ack().await.map_err(HandleMessageError::DoubleAck)?;
match message.subject.as_str(){ match message.subject.as_str(){
"maptest.submissions.publishnew"=>self.publish_new.publish(message).await.map_err(HandleMessageError::PublishNew), "maptest.submissions.publishnew"=>self.publish_new.publish(from_slice(&message.payload)?).await.map_err(HandleMessageError::PublishNew),
"maptest.submissions.publishfix"=>self.publish_fix.publish(message).await.map_err(HandleMessageError::PublishFix), "maptest.submissions.publishfix"=>self.publish_fix.publish(from_slice(&message.payload)?).await.map_err(HandleMessageError::PublishFix),
"maptest.submissions.validate"=>self.validator.validate(message).await.map_err(HandleMessageError::Validation), "maptest.submissions.validate"=>self.validator.validate(from_slice(&message.payload)?).await.map_err(HandleMessageError::Validation),
other=>Err(HandleMessageError::UnknownSubject(other.to_owned())) other=>Err(HandleMessageError::UnknownSubject(other.to_owned()))
} }
} }

View File

@ -32,11 +32,7 @@ impl Publisher{
api_internal, api_internal,
} }
} }
pub async fn publish(&self,message:async_nats::jetstream::Message)->Result<(),PublishError>{ pub async fn publish(&self,publish_info:PublishFixRequest)->Result<(),PublishError>{
println!("publish_fix {:?}",message.message.payload);
// decode json
let publish_info:PublishFixRequest=serde_json::from_slice(&message.payload).map_err(PublishError::Json)?;
// download the map model version // download the map model version
let model_data=self.roblox_cookie.get_asset(rbx_asset::cookie::GetAssetRequest{ let model_data=self.roblox_cookie.get_asset(rbx_asset::cookie::GetAssetRequest{
asset_id:publish_info.ModelID, asset_id:publish_info.ModelID,

View File

@ -33,11 +33,7 @@ impl Publisher{
api, api,
} }
} }
pub async fn publish(&self,message:async_nats::jetstream::Message)->Result<(),PublishError>{ pub async fn publish(&self,publish_info:PublishNewRequest)->Result<(),PublishError>{
println!("publish_new {:?}",message.message.payload);
// decode json
let publish_info:PublishNewRequest=serde_json::from_slice(&message.payload).map_err(PublishError::Json)?;
// download the map model version // download the map model version
let model_data=self.roblox_cookie.get_asset(rbx_asset::cookie::GetAssetRequest{ let model_data=self.roblox_cookie.get_asset(rbx_asset::cookie::GetAssetRequest{
asset_id:publish_info.ModelID, asset_id:publish_info.ModelID,

View File

@ -41,7 +41,6 @@ pub enum ValidateError{
Blocked, Blocked,
NotAllowed, NotAllowed,
Get(rbx_asset::cookie::GetError), Get(rbx_asset::cookie::GetError),
Json(serde_json::Error),
ReadDom(ReadDomError), ReadDom(ReadDomError),
ApiGetScriptPolicy(submissions_api::Error), ApiGetScriptPolicy(submissions_api::Error),
ApiGetScript(submissions_api::Error), ApiGetScript(submissions_api::Error),
@ -75,11 +74,29 @@ impl Validator{
api, api,
} }
} }
pub async fn validate(&self,message:async_nats::jetstream::Message)->Result<(),ValidateError>{ pub async fn validate(&self,validate_info:ValidateRequest)->Result<(),ValidateError>{
println!("validate {:?}",message.message.payload); let submission_id=validate_info.SubmissionID;
// decode json let validate_result=self.validate_inner(validate_info).await;
let validate_info:ValidateRequest=serde_json::from_slice(&message.payload).map_err(ValidateError::Json)?;
// update the submission depending on the result
match &validate_result{
Ok(())=>{
// update the submission model status to validated
self.api.action_submission_validated(
submissions_api::internal::SubmissionID(submission_id)
).await.map_err(ValidateError::ApiActionSubmissionValidate)?;
},
Err(_)=>{
// update the submission model status to accepted
self.api.action_submission_accepted(
submissions_api::internal::SubmissionID(submission_id)
).await.map_err(ValidateError::ApiActionSubmissionValidate)?;
},
}
validate_result
}
pub async fn validate_inner(&self,validate_info:ValidateRequest)->Result<(),ValidateError>{
// download map // download map
let data=self.roblox_cookie.get_asset(rbx_asset::cookie::GetAssetRequest{ let data=self.roblox_cookie.get_asset(rbx_asset::cookie::GetAssetRequest{
asset_id:validate_info.ModelID, asset_id:validate_info.ModelID,
@ -219,11 +236,6 @@ impl Validator{
}).await.map_err(ValidateError::ApiUpdateSubmissionModel)?; }).await.map_err(ValidateError::ApiUpdateSubmissionModel)?;
}; };
// update the submission model status to validated
self.api.action_submission_validated(
submissions_api::internal::SubmissionID(validate_info.SubmissionID)
).await.map_err(ValidateError::ApiActionSubmissionValidate)?;
Ok(()) Ok(())
} }
} }