From 329c0d0aefc1c1c5d0c3058a05a27ce03648677f Mon Sep 17 00:00:00 2001 From: "Dustin J. Mitchell" Date: Sun, 10 Oct 2021 01:33:45 +0000 Subject: [PATCH] move ServerConfig to crate::server --- sync-server/src/lib.rs | 33 ++------------------------------- sync-server/src/server.rs | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 32 deletions(-) diff --git a/sync-server/src/lib.rs b/sync-server/src/lib.rs index 012f0c43f..0ce33dbfe 100644 --- a/sync-server/src/lib.rs +++ b/sync-server/src/lib.rs @@ -6,10 +6,11 @@ pub mod storage; use crate::storage::Storage; use actix_web::{get, middleware, web, Responder}; -use anyhow::Context; use api::{api_scope, ServerState}; use std::sync::Arc; +pub use server::ServerConfig; + #[get("/")] async fn index() -> impl Responder { format!("TaskChampion sync server v{}", env!("CARGO_PKG_VERSION")) @@ -21,36 +22,6 @@ pub struct Server { server_state: Arc, } -/// ServerConfig contains configuration parameters for the server. -pub struct ServerConfig { - /// Target number of days between snapshots. - pub snapshot_days: i64, - - /// Target number of versions between snapshots. - pub snapshot_versions: u32, -} - -impl Default for ServerConfig { - fn default() -> Self { - ServerConfig { - snapshot_days: 14, - snapshot_versions: 100, - } - } -} -impl ServerConfig { - pub fn from_args(snapshot_days: &str, snapshot_versions: &str) -> anyhow::Result { - Ok(ServerConfig { - snapshot_days: snapshot_days - .parse() - .context("--snapshot-days must be a number")?, - snapshot_versions: snapshot_versions - .parse() - .context("--snapshot-days must be a number")?, - }) - } -} - impl Server { /// Create a new sync server with the given storage implementation. pub fn new(config: ServerConfig, storage: Box) -> Self { diff --git a/sync-server/src/server.rs b/sync-server/src/server.rs index c1947e0ca..f7b40a16a 100644 --- a/sync-server/src/server.rs +++ b/sync-server/src/server.rs @@ -2,7 +2,7 @@ //! invariants, and so on. This does not implement the HTTP-specific portions; those //! are in [`crate::api`]. See the protocol documentation for details. use crate::storage::{Client, Snapshot, StorageTxn}; -use crate::ServerConfig; // TODO: move here +use anyhow::Context; use chrono::Utc; use uuid::Uuid; @@ -18,6 +18,37 @@ pub(crate) type HistorySegment = Vec; pub(crate) type ClientKey = Uuid; pub(crate) type VersionId = Uuid; +/// ServerConfig contains configuration parameters for the server. +pub struct ServerConfig { + /// Target number of days between snapshots. + pub snapshot_days: i64, + + /// Target number of versions between snapshots. + pub snapshot_versions: u32, +} + +impl Default for ServerConfig { + fn default() -> Self { + ServerConfig { + snapshot_days: 14, + snapshot_versions: 100, + } + } +} + +impl ServerConfig { + pub fn from_args(snapshot_days: &str, snapshot_versions: &str) -> anyhow::Result { + Ok(ServerConfig { + snapshot_days: snapshot_days + .parse() + .context("--snapshot-days must be a number")?, + snapshot_versions: snapshot_versions + .parse() + .context("--snapshot-days must be a number")?, + }) + } +} + /// Response to get_child_version. See the protocol documentation. #[derive(Clone, PartialEq, Debug)] pub(crate) enum GetVersionResult {