mirror of
https://github.com/facebook/sapling.git
synced 2024-10-10 08:47:12 +03:00
mononoke: use strum for ScrubAction parsing
Summary: Removes the manual from_str impl Reviewed By: krallin Differential Revision: D25944622 fbshipit-source-id: 4e1e1113e0501c01435b287b165c0f1695729615
This commit is contained in:
parent
5285dd1b3c
commit
a5d86bdae9
@ -24,6 +24,8 @@ futures = { version = "0.3.5", features = ["async-await", "compat"] }
|
||||
itertools = "0.8"
|
||||
once_cell = "1.4"
|
||||
slog = { version = "2.5", features = ["max_level_debug"] }
|
||||
strum = "0.19"
|
||||
strum_macros = "0.19"
|
||||
thiserror = "1.0"
|
||||
tokio = { version = "=0.2.13", features = ["full", "test-util"] }
|
||||
twox-hash = "1.5"
|
||||
|
@ -10,7 +10,7 @@ use crate::{
|
||||
queue::MultiplexedBlobstore,
|
||||
};
|
||||
|
||||
use anyhow::{anyhow, Error, Result};
|
||||
use anyhow::Result;
|
||||
use async_trait::async_trait;
|
||||
use blobstore::{
|
||||
Blobstore, BlobstoreGetData, BlobstoreMetadata, BlobstorePutOps, OverwriteStatus, PutBehaviour,
|
||||
@ -27,14 +27,14 @@ use slog::{info, warn};
|
||||
use std::collections::HashMap;
|
||||
use std::fmt;
|
||||
use std::num::{NonZeroU64, NonZeroUsize};
|
||||
use std::str::FromStr;
|
||||
use std::sync::{atomic::AtomicUsize, Arc};
|
||||
use strum_macros::{EnumString, EnumVariantNames};
|
||||
|
||||
static DEFAULT_HEAL_MAX_BACKLOG_DAYS: i64 = 7;
|
||||
static HEAL_MAX_BACKLOG: OnceCell<ChronoDuration> = OnceCell::new();
|
||||
|
||||
/// What to do when the ScrubBlobstore finds a problem
|
||||
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
|
||||
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, EnumString, EnumVariantNames)]
|
||||
pub enum ScrubAction {
|
||||
/// Log items needing repair
|
||||
ReportOnly,
|
||||
@ -42,18 +42,6 @@ pub enum ScrubAction {
|
||||
Repair,
|
||||
}
|
||||
|
||||
impl FromStr for ScrubAction {
|
||||
type Err = Error;
|
||||
|
||||
fn from_str(string: &str) -> Result<Self, Self::Err> {
|
||||
match string {
|
||||
"ReportOnly" => Ok(ScrubAction::ReportOnly),
|
||||
"Repair" => Ok(ScrubAction::Repair),
|
||||
_ => Err(anyhow!("Unable to parse {} as {}", string, "ScrubAction")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ScrubOptions {
|
||||
pub scrub_action: ScrubAction,
|
||||
|
@ -162,7 +162,8 @@ pub async fn subcommand_blobstore_fetch<'a>(
|
||||
let scrub_action = sub_m
|
||||
.value_of(SCRUB_BLOBSTORE_ACTION_ARG)
|
||||
.map(ScrubAction::from_str)
|
||||
.transpose()?;
|
||||
.transpose()
|
||||
.map_err(Error::from)?;
|
||||
let mysql_options = args::parse_mysql_options(&matches);
|
||||
let blobstore_options = args::parse_blobstore_options(&matches).with_scrub_action(scrub_action);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user