summaryrefslogtreecommitdiff
path: root/src/dbctx.rs
diff options
context:
space:
mode:
authoriximeow <git@iximeow.net>2022-12-29 03:23:49 +0000
committeriximeow <git@iximeow.net>2022-12-29 03:23:49 +0000
commita7d2af2370ee186cdbf7f237a08754b9ed6991fd (patch)
treeaef84fec24d1f5f61264d278de9c409ded3c4681 /src/dbctx.rs
parentf6da9d6b9ffcdb8a4a30d7d9f28dd37b4afb143c (diff)
factor out io stuff
Diffstat (limited to 'src/dbctx.rs')
-rw-r--r--src/dbctx.rs49
1 files changed, 1 insertions, 48 deletions
diff --git a/src/dbctx.rs b/src/dbctx.rs
index cb74010..804f083 100644
--- a/src/dbctx.rs
+++ b/src/dbctx.rs
@@ -7,6 +7,7 @@ use tokio::io::{AsyncReadExt, AsyncWriteExt};
use std::path::Path;
use std::path::PathBuf;
+use crate::io::ArtifactDescriptor;
use crate::notifier::{RemoteNotifier, NotifierConfig};
use crate::sql;
@@ -45,54 +46,6 @@ pub struct ArtifactRecord {
pub desc: String
}
-pub struct ArtifactDescriptor {
- job_id: u64,
- artifact_id: u64,
- file: File,
-}
-
-impl ArtifactDescriptor {
- async fn new(job_id: u64, artifact_id: u64) -> Result<Self, String> {
- // TODO: jobs should be a configurable path
- let path = format!("jobs/{}/{}", job_id, artifact_id);
- let file = OpenOptions::new()
- .read(true)
- .write(true)
- .create_new(true)
- .open(&path)
- .await
- .map_err(|e| format!("couldn't open artifact file {}: {}", path, e))?;
-
- Ok(ArtifactDescriptor {
- job_id,
- artifact_id,
- file,
- })
- }
-
- pub async fn store_all(&mut self, mut data: axum::extract::BodyStream) -> Result<(), String> {
- loop {
- let chunk = data.next().await;
-
- let chunk = match chunk {
- Some(Ok(chunk)) => chunk,
- Some(Err(e)) => {
- return Err(format!("error reading: {:?}", e));
- }
- None => {
- eprintln!("body done?");
- return Ok(());
- }
- };
-
- let chunk = chunk.as_ref();
-
- self.file.write_all(chunk).await
- .map_err(|e| format!("failed to write: {:?}", e))?;
- }
- }
-}
-
impl DbCtx {
pub fn new<P: AsRef<Path>>(config_path: P, db_path: P) -> Self {
DbCtx {