diff --git a/services/backup/src/service/handlers/pull_backup.rs b/services/backup/src/service/handlers/pull_backup.rs new file mode 100644 --- /dev/null +++ b/services/backup/src/service/handlers/pull_backup.rs @@ -0,0 +1,34 @@ +use tokio_stream::Stream; +use tonic::Status; + +use super::proto::{self, PullBackupResponse}; +use crate::database::{BackupItem, DatabaseClient, LogItem}; + +pub struct PullBackupHandler { + backup_item: BackupItem, + logs: Vec, +} + +impl PullBackupHandler { + pub async fn new( + db: &DatabaseClient, + request: proto::PullBackupRequest, + ) -> Result { + unimplemented!() + } + + /// Consumes the handler and provides a response `Stream`. The stream will + /// produce the following in order: + /// - Backup compaction data chunks + /// - Backup logs + /// - Whole log, if stored in db + /// - Log chunks, if stored in blob + pub fn into_response_stream( + self, + ) -> impl Stream> { + // the unimplemented!() macro doesnt compile here + async_stream::stream! { + yield Err(Status::unimplemented("not implemented yet")) + } + } +} diff --git a/services/backup/src/service/mod.rs b/services/backup/src/service/mod.rs --- a/services/backup/src/service/mod.rs +++ b/services/backup/src/service/mod.rs @@ -20,6 +20,7 @@ mod handlers { pub(super) mod add_attachments; pub(super) mod create_backup; + pub(super) mod pull_backup; pub(super) mod send_log; // re-exports for convenient usage in handlers @@ -27,6 +28,7 @@ pub(self) use super::proto; } use self::handlers::create_backup::CreateBackupHandler; +use self::handlers::pull_backup::PullBackupHandler; use self::handlers::send_log::SendLogHandler; pub struct MyBackupService { @@ -172,12 +174,18 @@ Box> + Send>, >; - #[instrument(skip(self))] + #[instrument(skip_all, fields(backup_id = &request.get_ref().backup_id))] async fn pull_backup( &self, - _request: Request, + request: Request, ) -> Result, Status> { - Err(Status::unimplemented("unimplemented")) + info!("PullBackup request: {:?}", request); + + let handler = + PullBackupHandler::new(&self.db, request.into_inner()).await?; + + let stream = handler.into_response_stream(); + Ok(Response::new(Box::pin(stream) as Self::PullBackupStream)) } #[instrument(skip_all,