Skip to content

Commit

Permalink
refactor pgpool, version bumps
Browse files Browse the repository at this point in the history
  • Loading branch information
ddboline committed Jul 6, 2024
1 parent 1ac680f commit 8c03554
Show file tree
Hide file tree
Showing 28 changed files with 92 additions and 109 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "garmin_rust"
version = "0.14.17"
version = "0.14.18"
authors = ["Daniel Boline <[email protected]>"]
edition = "2018"

Expand All @@ -26,7 +26,7 @@ garmin_utils = {path="garmin_utils"}
log = "0.4"
stack-string = { git = "https://github.com/ddboline/stack-string-rs.git", features=["postgres_types"], tag="0.9.3" }
tempdir = "0.3"
tokio = {version="1.37", features=["rt", "macros", "rt-multi-thread"]}
tokio = {version="1.38", features=["rt", "macros", "rt-multi-thread"]}

[workspace]
members = [
Expand Down
6 changes: 3 additions & 3 deletions fitbit_bot/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fitbit_bot"
version = "0.14.17"
version = "0.14.18"
authors = ["Daniel Boline <[email protected]>"]
edition = "2018"

Expand All @@ -19,10 +19,10 @@ once_cell = "1.0"
parking_lot = "0.12"
stack-string = { git = "https://github.com/ddboline/stack-string-rs.git", features=["postgres_types"], tag="0.9.3" }
telegram-bot = {git = "https://github.com/ddboline/telegram-bot.git", tag="0.9.0-4", default_features=false}
tokio = {version="1.37", features=["rt", "macros", "rt-multi-thread"]}
tokio = {version="1.38", features=["rt", "macros", "rt-multi-thread"]}

[dev-dependencies]
maplit = "1.0"
rand = "0.8"
postgres_query = {git = "https://github.com/ddboline/rust-postgres-query", tag = "0.3.7", features=["deadpool"]}
postgres_query = {git = "https://github.com/ddboline/rust-postgres-query", tag = "0.3.8", features=["deadpool"]}
uuid = { version = "1.0", features = ["serde", "v4"] }
6 changes: 3 additions & 3 deletions fitbit_bot/src/telegram_bot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ mod tests {
let user: UserId = 8675309.into();

let config = GarminConfig::get_config(None)?;
let pool = PgPool::new(&config.pgurl);
let pool = PgPool::new(&config.pgurl)?;

let bot = TelegramBot::new("8675309", &pool, &config);

Expand Down Expand Up @@ -302,7 +302,7 @@ mod tests {
let mut exp = ScaleMeasurement::from_telegram_text(msg)?;

let config = GarminConfig::get_config(None)?;
let pool = PgPool::new(&config.pgurl);
let pool = PgPool::new(&config.pgurl)?;
let bot = TelegramBot::new("8675309", &pool, &config);

exp.insert_into_db(&pool).await?;
Expand Down Expand Up @@ -333,7 +333,7 @@ mod tests {
USERIDS.store(Arc::new(HashSet::new()));

let config = GarminConfig::get_config(None)?;
let pool = PgPool::new(&config.pgurl);
let pool = PgPool::new(&config.pgurl)?;
let bot = TelegramBot::new("8675309", &pool, &config);

let email = format_sstr!("user{}@localhost", get_random_string(32));
Expand Down
10 changes: 5 additions & 5 deletions fitbit_lib/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fitbit_lib"
version = "0.14.17"
version = "0.14.18"
authors = ["Daniel Boline <[email protected]>"]
edition = "2018"

Expand All @@ -19,12 +19,12 @@ garmin_lib = {path = "../garmin_lib"}
garmin_models = {path="../garmin_models"}
garmin_utils = {path="../garmin_utils"}
glob = "0.3"
itertools = "0.12"
itertools = "0.13"
log = "0.4"
maplit = "1.0"
once_cell = "1.0"
polars = {version="0.39", features=["temporal", "parquet", "lazy"]}
postgres_query = {git = "https://github.com/ddboline/rust-postgres-query", tag = "0.3.7", features=["deadpool"]}
polars = {version="0.41", features=["temporal", "parquet", "lazy"]}
postgres_query = {git = "https://github.com/ddboline/rust-postgres-query", tag = "0.3.8", features=["deadpool"]}
rand = "0.8"
rayon = "1.5"
reqwest = {version="0.12", features=["cookies", "json", "rustls-tls", "stream"], default_features=false}
Expand All @@ -35,7 +35,7 @@ stack-string = { git = "https://github.com/ddboline/stack-string-rs.git", featur
statistical = "1.0"
time = {version="0.3", features=["serde-human-readable", "macros", "formatting", "parsing"]}
time-tz = {version="2.0", features=["system"]}
tokio = {version="1.37", features=["rt", "macros", "rt-multi-thread"]}
tokio = {version="1.38", features=["rt", "macros", "rt-multi-thread"]}
uuid = { version = "1.0", features = ["serde", "v4"] }

[dev-dependencies]
Expand Down
11 changes: 4 additions & 7 deletions fitbit_lib/src/fitbit_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1135,10 +1135,7 @@ mod tests {
use log::debug;
use std::collections::HashMap;
use tempfile::NamedTempFile;
use time::{
macros::{date, format_description},
Date, Duration, OffsetDateTime,
};
use time::{macros::format_description, Duration, OffsetDateTime};
use time_tz::OffsetDateTimeExt;

use garmin_lib::{date_time_wrapper::DateTimeWrapper, garmin_config::GarminConfig};
Expand Down Expand Up @@ -1242,7 +1239,7 @@ mod tests {

let begin_datetime = OffsetDateTime::now_utc() - Duration::days(30);

let pool = PgPool::new(&config.pgurl);
let pool = PgPool::new(&config.pgurl)?;
let dates = client.sync_fitbit_activities(begin_datetime, &pool).await?;
debug!("{:?}", dates);
assert_eq!(dates.len(), 0);
Expand All @@ -1265,7 +1262,7 @@ mod tests {
async fn test_dump_fitbit_activities() -> Result<(), Error> {
let config = GarminConfig::get_config(None)?;
let client = FitbitClient::with_auth(config.clone()).await?;
let pool = PgPool::new(&config.pgurl);
let pool = PgPool::new(&config.pgurl)?;
let mut activities: HashMap<_, _> = FitbitActivity::read_from_db(&pool, None, None)
.await?
.into_iter()
Expand Down Expand Up @@ -1301,7 +1298,7 @@ mod tests {
#[ignore]
async fn test_delete_duplicate_activities() -> Result<(), Error> {
let config = GarminConfig::get_config(None)?;
let pool = PgPool::new(&config.pgurl);
let pool = PgPool::new(&config.pgurl)?;
let client = FitbitClient::with_auth(config.clone()).await?;

let output = client.remove_duplicate_entries(&pool).await?;
Expand Down
2 changes: 1 addition & 1 deletion fitbit_lib/src/fitbit_heartrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ mod tests {
#[ignore]
async fn test_calculate_summary_statistics() -> Result<(), Error> {
let config = GarminConfig::get_config(None)?;
let pool = PgPool::new(&config.pgurl);
let pool = PgPool::new(&config.pgurl)?;
let start_date = date!(2019 - 08 - 01);
let result =
FitbitHeartRate::calculate_summary_statistics(&config, &pool, start_date).await?;
Expand Down
2 changes: 1 addition & 1 deletion fitbit_lib/src/scale_measurement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ mod tests {
};

let config = GarminConfig::get_config(None)?;
let pool = PgPool::new(&config.pgurl);
let pool = PgPool::new(&config.pgurl)?;

exp.insert_into_db(&pool).await?;

Expand Down
6 changes: 3 additions & 3 deletions garmin_cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "garmin_cli"
version = "0.14.17"
version = "0.14.18"
authors = ["Daniel Boline <[email protected]>"]
edition = "2018"

Expand All @@ -18,7 +18,7 @@ garmin_models={path="../garmin_models"}
garmin_parser={path="../garmin_parser"}
garmin_reports = {path="../garmin_reports"}
garmin_utils={path="../garmin_utils"}
itertools = "0.12"
itertools = "0.13"
log = "0.4"
race_result_analysis = {path="../race_result_analysis"}
rayon = "1.5"
Expand All @@ -30,7 +30,7 @@ strava_lib = {path="../strava_lib"}
tempdir = "0.3"
time = {version="0.3", features=["serde-human-readable", "macros", "formatting", "parsing"]}
time-tz = {version="2.0", features=["system"]}
tokio = {version="1.37", features=["rt", "macros", "rt-multi-thread"]}
tokio = {version="1.38", features=["rt", "macros", "rt-multi-thread"]}
tokio-postgres = {version = "0.7", features = ["with-time-0_3"]}
stack-string = { git = "https://github.com/ddboline/stack-string-rs.git", features=["postgres_types"], tag="0.9.3" }
stdout-channel = "0.6"
49 changes: 20 additions & 29 deletions garmin_cli/src/garmin_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl GarminCli {
/// Return error if config init fails
pub fn with_config() -> Result<Self, Error> {
let config = GarminConfig::get_config(None)?;
let pool = PgPool::new(&config.pgurl);
let pool = PgPool::new(&config.pgurl)?;
let corr = GarminCorrectionMap::new();
let obj = Self {
config,
Expand Down Expand Up @@ -152,23 +152,22 @@ impl GarminCli {
&self,
corr_map: &HashMap<(DateTimeWrapper, i32), GarminCorrectionLap>,
) -> Result<Vec<GarminSummary>, Error> {
let config = self.get_config();
let pg_conn = self.get_pool();

let mut gsum_list: Vec<_> = match self.get_opts() {
Some(GarminCliOptions::FileNames(flist)) => flist
.par_iter()
.map(|f| {
self.stdout.send(format_sstr!("Process {f:?}"));
GarminParse::process_single_gps_file(f, &self.get_config().cache_dir, corr_map)
GarminParse::process_single_gps_file(f, &config.cache_dir, corr_map)
})
.collect::<Result<Vec<_>, Error>>()?,
Some(GarminCliOptions::All) => GarminParse::process_all_gps_files(
&self.get_config().gps_dir,
&self.get_config().cache_dir,
corr_map,
)?,
Some(GarminCliOptions::All) => {
GarminParse::process_all_gps_files(&config.gps_dir, &config.cache_dir, corr_map)?
}
_ => {
let cacheset: HashSet<StackString> = get_file_list(&self.get_config().cache_dir)
let cacheset: HashSet<StackString> = get_file_list(&config.cache_dir)
.into_par_iter()
.filter_map(|f| {
if f.to_string_lossy().contains("garmin_correction.avro") {
Expand All @@ -185,26 +184,20 @@ impl GarminCli {
.try_collect()
.await?;

get_file_list(&self.get_config().gps_dir)
get_file_list(&config.gps_dir)
.into_par_iter()
.filter_map(|f| f.file_name().map(|x| x.to_string_lossy().to_string()))
.filter_map(|f| {
let cachefile = format_sstr!("{f}.avro");
if dbset.contains(f.as_str()) && cacheset.contains(cachefile.as_str()) {
None
} else {
let gps_path = self.get_config().gps_dir.join(&f);
let gps_path = config.gps_dir.join(&f);
debug!("Process {:?}", &gps_path);
Some(gps_path)
}
})
.map(|f| {
GarminParse::process_single_gps_file(
&f,
&self.get_config().cache_dir,
corr_map,
)
})
.map(|f| GarminParse::process_single_gps_file(&f, &config.cache_dir, corr_map))
.collect::<Result<Vec<_>, Error>>()?
}
};
Expand All @@ -221,29 +214,26 @@ impl GarminCli {
/// # Errors
/// Return error if `sync_dir` fails
pub async fn sync_everything(&self) -> Result<Vec<StackString>, Error> {
let config = self.get_config();
let sdk_config = aws_config::load_from_env().await;
let gsync = GarminSync::new(&sdk_config);

let options = vec![
(
"Syncing GPS files",
&self.get_config().gps_dir,
&self.get_config().gps_bucket,
),
("Syncing GPS files", &config.gps_dir, &config.gps_bucket),
(
"Syncing CACHE files",
&self.get_config().cache_dir,
&self.get_config().cache_bucket,
&config.cache_dir,
&config.cache_bucket,
),
(
"Syncing Fitbit Cache",
&self.get_config().fitbit_cachedir,
&self.get_config().fitbit_bucket,
&config.fitbit_cachedir,
&config.fitbit_bucket,
),
(
"Syncing Fitbit Archive",
&self.get_config().fitbit_archivedir,
&self.get_config().fitbit_archive_bucket,
&config.fitbit_archivedir,
&config.fitbit_archive_bucket,
),
];

Expand Down Expand Up @@ -282,6 +272,7 @@ impl GarminCli {
options: &GarminReportOptions,
constraints: &GarminConstraints,
) -> Result<(), Error> {
let config = self.get_config();
let pg_conn = self.get_pool();
let mut file_list: Vec<_> =
get_list_of_files_from_db(&constraints.to_query_string(), &pg_conn)
Expand Down Expand Up @@ -309,7 +300,7 @@ impl GarminCli {
debug!("Cached avro file read: {:?}", &avro_file);
g
} else {
let gps_file = self.get_config().gps_dir.join(file_name.as_str());
let gps_file = config.gps_dir.join(file_name.as_str());
let pool = self.get_pool();
let mut corr_map = GarminCorrectionLap::read_corrections_from_db(&pool).await?;
corr_map.shrink_to_fit();
Expand Down
4 changes: 2 additions & 2 deletions garmin_cli/src/garmin_cli_opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ impl GarminCliOpts {
}

async fn process_opts(self, config: &GarminConfig) -> Result<(), Error> {
let pool = PgPool::new(&config.pgurl);
let pool = PgPool::new(&config.pgurl)?;

let opts = match self {
Self::Bootstrap => GarminCliOptions::Bootstrap,
Expand Down Expand Up @@ -666,7 +666,7 @@ mod tests {
async fn test_garmin_file_test_filenames() -> Result<(), Error> {
let test_config = "tests/data/test.env";
let config = GarminConfig::get_config(Some(test_config))?;
let pool = PgPool::new(&config.pgurl);
let pool = PgPool::new(&config.pgurl)?;
let corr = GarminCorrectionMap::new();

let gcli = GarminCli {
Expand Down
6 changes: 3 additions & 3 deletions garmin_connect_lib/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "garmin_connect_lib"
version = "0.14.17"
version = "0.14.18"
authors = ["Daniel Boline <[email protected]>"]
edition = "2018"

Expand All @@ -13,7 +13,7 @@ derive_more = "0.99"
fantoccini = {version="0.19", features=["rustls-tls"], default_features=false}
futures = "0.3"
garmin_lib = {path="../garmin_lib"}
itertools = "0.12"
itertools = "0.13"
log = "0.4"
reqwest = {version="0.12", features=["cookies", "json", "rustls-tls", "stream"], default_features=false}
serde = {version="1.0", features=["derive"]}
Expand All @@ -22,5 +22,5 @@ smallvec = "1.6"
stack-string = { git = "https://github.com/ddboline/stack-string-rs.git", features=["postgres_types"], tag="0.9.3" }
time = {version="0.3", features=["serde-human-readable", "macros", "formatting", "parsing"]}
time-tz = {version="2.0", features=["system"]}
tokio = {version="1.37", features=["rt", "macros", "rt-multi-thread"]}
tokio = {version="1.38", features=["rt", "macros", "rt-multi-thread"]}
url = "2.3"
10 changes: 5 additions & 5 deletions garmin_http/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[package]
name = "garmin_http"
version = "0.14.17"
version = "0.14.18"
authors = ["Daniel Boline <[email protected]>"]
edition = "2018"

[dependencies]
anyhow = "1.0"
authorized_users = { git = "https://github.com/ddboline/auth_server_rust.git", tag="0.11.14"}
authorized_users = { git = "https://github.com/ddboline/auth_server_rust.git", tag="0.11.15"}
base64 = "0.22"
cookie = {version="0.18", features=["percent-encode"]}
derive_more = "0.99"
Expand All @@ -22,11 +22,11 @@ garmin_parser = {path="../garmin_parser"}
garmin_reports = {path="../garmin_reports"}
garmin_utils = {path="../garmin_utils"}
handlebars = "5.1"
itertools = "0.12"
itertools = "0.13"
log = "0.4"
maplit = "1.0"
parking_lot = "0.12"
postgres_query = {git = "https://github.com/ddboline/rust-postgres-query", tag = "0.3.7", features=["deadpool"]}
postgres_query = {git = "https://github.com/ddboline/rust-postgres-query", tag = "0.3.8", features=["deadpool"]}
race_result_analysis = {path="../race_result_analysis"}
reqwest = {version="0.12", features=["cookies", "json", "rustls-tls", "stream"], default_features=false}
rweb = {git = "https://github.com/ddboline/rweb.git", features=["openapi"], default-features=false, tag="0.15.2"}
Expand All @@ -41,7 +41,7 @@ tempdir = "0.3"
thiserror = "1.0"
time = {version="0.3", features=["serde-human-readable", "macros", "formatting", "parsing"]}
time-tz = {version="2.0", features=["system"]}
tokio = {version="1.37", features=["rt", "macros", "rt-multi-thread"]}
tokio = {version="1.38", features=["rt", "macros", "rt-multi-thread"]}
tokio-stream = "0.1"
url = "2.3"
uuid = "1.0"
2 changes: 1 addition & 1 deletion garmin_http/src/garmin_elements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ fn IndexElement(
);
let mut final_values: Vec<_> = heartrate
.iter()
.group_by(|(d, _)| d.unix_timestamp() / (5 * 60))
.chunk_by(|(d, _)| d.unix_timestamp() / (5 * 60))
.into_iter()
.map(|(_, group)| {
let (begin_datetime, entries, heartrate_sum) = group.fold(
Expand Down
Loading

0 comments on commit 8c03554

Please sign in to comment.