Background task manager #332
3 changed files with 19 additions and 7 deletions
|
@ -1,7 +1,12 @@
|
||||||
[package]
|
[package]
|
||||||
name = "k2v-client"
|
name = "k2v-client"
|
||||||
version = "0.1.0"
|
version = "0.0.1"
|
||||||
|
authors = ["Trinity Pointard <trinity.pointard@gmail.com>", "Alex Auvolat <alex@adnab.me>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
license = "AGPL-3.0"
|
||||||
|
description = "Client library for the Garage K2V protocol"
|
||||||
|
repository = "https://git.deuxfleurs.fr/Deuxfleurs/garage"
|
||||||
|
readme = "../../README.md"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
base64 = "0.13.0"
|
base64 = "0.13.0"
|
||||||
|
@ -17,7 +22,7 @@ tokio = "1.17.0"
|
||||||
|
|
||||||
# cli deps
|
# cli deps
|
||||||
clap = { version = "3.1.18", optional = true, features = ["derive", "env"] }
|
clap = { version = "3.1.18", optional = true, features = ["derive", "env"] }
|
||||||
garage_util = { path = "../util", optional = true }
|
garage_util = { version = "0.7.0", path = "../util", optional = true }
|
||||||
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
use k2v_client::*;
|
use k2v_client::*;
|
||||||
|
|
||||||
use garage_util::formater::format_table;
|
use garage_util::formater::format_table;
|
||||||
|
@ -64,6 +66,9 @@ enum Command {
|
||||||
/// Causality information
|
/// Causality information
|
||||||
#[clap(short, long)]
|
#[clap(short, long)]
|
||||||
causality: String,
|
causality: String,
|
||||||
|
/// Timeout, in seconds
|
||||||
|
#[clap(short, long)]
|
||||||
|
timeout: Option<u64>,
|
||||||
/// Output formating
|
/// Output formating
|
||||||
#[clap(flatten)]
|
#[clap(flatten)]
|
||||||
output_kind: ReadOutputKind,
|
output_kind: ReadOutputKind,
|
||||||
|
@ -341,10 +346,12 @@ async fn main() -> Result<(), Error> {
|
||||||
partition_key,
|
partition_key,
|
||||||
sort_key,
|
sort_key,
|
||||||
causality,
|
causality,
|
||||||
|
timeout,
|
||||||
output_kind,
|
output_kind,
|
||||||
} => {
|
} => {
|
||||||
|
let timeout = timeout.map(Duration::from_secs);
|
||||||
let res_opt = client
|
let res_opt = client
|
||||||
.poll_item(&partition_key, &sort_key, causality.into(), None)
|
.poll_item(&partition_key, &sort_key, causality.into(), timeout)
|
||||||
.await?;
|
.await?;
|
||||||
if let Some(res) = res_opt {
|
if let Some(res) = res_opt {
|
||||||
output_kind.display_output(res);
|
output_kind.display_output(res);
|
||||||
|
|
|
@ -122,14 +122,14 @@ impl K2vClient {
|
||||||
|
|
||||||
let res = self.dispatch(req, Some(timeout + DEFAULT_TIMEOUT)).await?;
|
let res = self.dispatch(req, Some(timeout + DEFAULT_TIMEOUT)).await?;
|
||||||
|
|
||||||
let causality = res
|
|
||||||
.causality_token
|
|
||||||
.ok_or_else(|| Error::InvalidResponse("missing causality token".into()))?;
|
|
||||||
|
|
||||||
if res.status == StatusCode::NOT_MODIFIED {
|
if res.status == StatusCode::NOT_MODIFIED {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let causality = res
|
||||||
|
.causality_token
|
||||||
|
.ok_or_else(|| Error::InvalidResponse("missing causality token".into()))?;
|
||||||
|
|
||||||
if res.status == StatusCode::NO_CONTENT {
|
if res.status == StatusCode::NO_CONTENT {
|
||||||
return Ok(Some(CausalValue {
|
return Ok(Some(CausalValue {
|
||||||
causality,
|
causality,
|
||||||
|
|
Loading…
Reference in a new issue