Page MenuHomePhabricator

D6165.diff
No OneTemporary

D6165.diff

diff --git a/services/backup/build.rs b/services/backup/build.rs
--- a/services/backup/build.rs
+++ b/services/backup/build.rs
@@ -2,6 +2,9 @@
println!("cargo:rerun-if-changed=src/main.rs");
println!("cargo:rerun-if-changed=../../shared/protos/backup.proto");
+ println!("cargo:rerun-if-changed=../../shared/protos/blob.proto");
tonic_build::compile_protos("../../shared/protos/backup.proto")
- .expect("Failed to compile protobuf file");
+ .expect("Failed to compile Backup protobuf file");
+ tonic_build::compile_protos("../../shared/protos/blob.proto")
+ .expect("Failed to compile Blob protobuf file");
}
diff --git a/services/backup/src/blob/get_client.rs b/services/backup/src/blob/get_client.rs
new file mode 100644
--- /dev/null
+++ b/services/backup/src/blob/get_client.rs
@@ -0,0 +1,38 @@
+use anyhow::Result;
+use tokio::{sync::mpsc::Receiver, task::JoinHandle};
+use tracing::instrument;
+
+use super::proto;
+pub use proto::put_request::Data as PutRequestData;
+pub use proto::{PutRequest, PutResponse};
+
+pub struct GetClient {
+ rx: Receiver<Vec<u8>>,
+ handle: JoinHandle<anyhow::Result<()>>,
+}
+
+impl GetClient {
+ /// Connects to the Blob service and keeps the client connection open
+ /// in a separate Tokio task.
+ #[instrument(name = "get_client")]
+ pub async fn start(holder: String) -> Result<Self> {
+ todo!()
+ }
+
+ /// Receives the next chunk of blob data if ready or sleeps
+ /// until the data is available.
+ ///
+ /// Returns `None` when the transmission is finished, but this doesn't
+ /// determine if it was successful. After receiving `None`, the client
+ /// should be consumed by calling [`GetClient::terminate`] to handle
+ /// possible errors.
+ pub async fn get(&mut self) -> Option<Vec<u8>> {
+ todo!()
+ }
+
+ /// Stops receiving messages and awaits the client thread to exit
+ /// and returns its status.
+ pub async fn terminate(mut self) -> Result<()> {
+ todo!()
+ }
+}
diff --git a/services/backup/src/blob/mod.rs b/services/backup/src/blob/mod.rs
new file mode 100644
--- /dev/null
+++ b/services/backup/src/blob/mod.rs
@@ -0,0 +1,10 @@
+mod proto {
+ tonic::include_proto!("blob");
+}
+pub use proto::put_request::Data as PutRequestData;
+pub use proto::{PutRequest, PutResponse};
+
+mod get_client;
+mod put_client;
+pub use get_client::*;
+pub use put_client::*;
diff --git a/services/backup/src/blob/put_client.rs b/services/backup/src/blob/put_client.rs
new file mode 100644
--- /dev/null
+++ b/services/backup/src/blob/put_client.rs
@@ -0,0 +1,37 @@
+use anyhow::Result;
+use tokio::{
+ sync::mpsc::{Receiver, Sender},
+ task::JoinHandle,
+};
+use tracing::instrument;
+
+use super::proto;
+pub use proto::put_request::Data as PutRequestData;
+pub use proto::{PutRequest, PutResponse};
+
+pub struct PutClient {
+ req_tx: Sender<proto::PutRequest>,
+ res_rx: Receiver<proto::PutResponse>,
+ handle: JoinHandle<anyhow::Result<()>>,
+}
+
+impl PutClient {
+ /// Connects to the Blob service and keeps the client connection open
+ /// in a separate Tokio task.
+ #[instrument(name = "put_client")]
+ pub async fn start() -> Result<Self> {
+ todo!()
+ }
+
+ /// Sends a [`PutRequest`] to the stream and waits for blob service
+ /// to send a response. After all data is sent, the [`PutClient::terminate`]
+ /// should be called to end the transmission and handle possible errors.
+ pub async fn put(&mut self, req: PutRequest) -> Result<PutResponse> {
+ todo!()
+ }
+
+ /// Closes the connection and awaits the blob client task to finish.
+ pub async fn terminate(self) -> Result<()> {
+ todo!()
+ }
+}
diff --git a/services/backup/src/main.rs b/services/backup/src/main.rs
--- a/services/backup/src/main.rs
+++ b/services/backup/src/main.rs
@@ -6,6 +6,7 @@
use crate::service::{BackupServiceServer, MyBackupService};
+pub mod blob;
pub mod config;
pub mod constants;
pub mod service;

File Metadata

Mime Type
text/plain
Expires
Thu, Dec 19, 7:54 PM (20 h, 32 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2678711
Default Alt Text
D6165.diff (3 KB)

Event Timeline