This repository has been archived by the owner on Aug 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip(backend): add async background worker
- Loading branch information
Showing
6 changed files
with
79 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use serde::{Deserialize, Serialize}; | ||
use tokio::sync::mpsc::Receiver; | ||
|
||
use crate::catalog::{execute_command, ExecValidateScriptRequest, JobResults}; | ||
use crate::yaml_config::CatalogServiceYamlConfig; | ||
|
||
#[derive(Serialize, Deserialize)] | ||
pub struct BackgroundWorkerTask { | ||
pub catalog_slug: String, | ||
pub catalog_service_yaml_config: CatalogServiceYamlConfig, | ||
pub req: ExecValidateScriptRequest, | ||
} | ||
|
||
impl BackgroundWorkerTask { | ||
pub fn new( | ||
catalog_slug: String, | ||
catalog_service_yaml_config: CatalogServiceYamlConfig, | ||
req: ExecValidateScriptRequest, | ||
) -> Self { | ||
Self { | ||
catalog_slug, | ||
catalog_service_yaml_config, | ||
req, | ||
} | ||
} | ||
} | ||
|
||
pub async fn background_worker(mut rx: Receiver<BackgroundWorkerTask>) { | ||
while let Some(task) = rx.recv().await { | ||
let mut job_results = JobResults { | ||
user_fields_input: task.req.payload.clone(), | ||
results: vec![], | ||
}; | ||
|
||
for cmd in task.catalog_service_yaml_config.post_validate.as_ref().unwrap_or(&vec![]) { | ||
let job_output_result = match execute_command(cmd, task.req.payload.to_string().as_str()).await { | ||
Ok(job_output_result) => job_output_result, | ||
Err(err) => todo!("{}", err) // TODO persist error in database | ||
}; | ||
|
||
let _ = job_results.results.push(job_output_result); | ||
} | ||
|
||
println!("job_results: {:?}", job_results); | ||
|
||
// TODO persist results in database | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters