Skip to content

Commit

Permalink
indexer-alt: fix connection timeout
Browse files Browse the repository at this point in the history
## Description

Using `stringify!(DEFAULT...)` doesn't work, because it stringifies the
constant name, not its contents. This change uses `const_str::format` to
do the same thing instead.

## Test plan

Run the indexer without supplying a connection timeout. Before this
change it would fail with a parse int error, because it tried to
interpret the string `DEFAULT_CONNECTION_TIMEOUT_SECS` as an integer.
  • Loading branch information
amnn committed Nov 2, 2024
1 parent 0753931 commit b680adb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
15 changes: 15 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/sui-indexer-alt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ bb8 = "0.8.5"
bcs.workspace = true
chrono.workspace = true
clap.workspace = true
const-str = { workspace = true, features = ["proc"] }
diesel = { workspace = true, features = ["chrono"] }
diesel-async = { workspace = true, features = ["bb8", "postgres", "async-connection-wrapper"] }
diesel_migrations.workspace = true
Expand Down
3 changes: 2 additions & 1 deletion crates/sui-indexer-alt/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

use anyhow::anyhow;
use const_str::format as const_format;
use diesel::migration::MigrationVersion;
use diesel_async::async_connection_wrapper::AsyncConnectionWrapper;
use diesel_async::{
Expand Down Expand Up @@ -38,7 +39,7 @@ pub struct DbConfig {
/// Time spent waiting for a connection from the pool to become available.
#[arg(
long,
default_value = stringify!(DEFAULT_CONNECTION_TIMEOUT_SECS),
default_value = const_format!("{DEFAULT_CONNECTION_TIMEOUT_SECS}"),
value_name = "SECONDS",
value_parser = |s: &str| s.parse().map(Duration::from_secs)
)]
Expand Down

0 comments on commit b680adb

Please sign in to comment.