Skip to content

Commit

Permalink
Working on intervals
Browse files Browse the repository at this point in the history
  • Loading branch information
scx1332 committed Oct 25, 2023
1 parent c273017 commit d70b1ca
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 3 deletions.
2 changes: 2 additions & 0 deletions config-payments.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[engine]
# proces interval (in seconds) is to set how often we want to check for transaction
process-interval = 5
# proces interval after error (in seconds) is to set how long to wait after encountering error before trying again
process-interval-after-error = 15
# gather interval (in seconds) is to set how often payments are gathered
gather-interval = 600
# gather payments on payment driver start (otherwise wait for first gather-sleep)
Expand Down
1 change: 1 addition & 0 deletions crates/erc20_payment_lib/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ impl AdditionalOptions {
#[serde(rename_all = "kebab-case")]
pub struct Engine {
pub process_interval: u64,
pub process_interval_after_error: u64,
pub gather_interval: u64,
pub gather_at_start: bool,
pub automatic_recover: bool,
Expand Down
1 change: 1 addition & 0 deletions crates/erc20_payment_lib/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ impl PaymentRuntime {
options.generate_tx_only,
options.skip_multi_contract_check,
config.engine.process_interval,
config.engine.process_interval_after_error,
config.engine.gather_interval,
config.engine.gather_at_start,
config.engine.automatic_recover,
Expand Down
5 changes: 4 additions & 1 deletion crates/erc20_payment_lib/src/sender/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,10 @@ pub async fn service_loop(
.await
{
log::error!("Error in process transactions: {}", e);
tokio::time::sleep(std::time::Duration::from_secs(10)).await;
tokio::time::sleep(std::time::Duration::from_secs(
payment_setup.process_interval,
))
.await;
continue;
}

Expand Down
3 changes: 3 additions & 0 deletions crates/erc20_payment_lib/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ pub struct PaymentSetup {
pub generate_tx_only: bool,
pub skip_multi_contract_check: bool,
pub process_interval: u64,
pub process_interval_after_error: u64,
pub gather_interval: u64,
pub gather_at_start: bool,
pub automatic_recover: bool,
Expand All @@ -79,6 +80,7 @@ impl PaymentSetup {
generate_txs_only: bool,
skip_multi_contract_check: bool,
process_interval: u64,
process_interval_after_error: u64,
gather_interval: u64,
gather_at_start: bool,
automatic_recover: bool,
Expand All @@ -91,6 +93,7 @@ impl PaymentSetup {
generate_tx_only: generate_txs_only,
skip_multi_contract_check,
process_interval,
process_interval_after_error,
gather_interval,
gather_at_start,
automatic_recover,
Expand Down
3 changes: 2 additions & 1 deletion crates/erc20_payment_lib_extra/src/account_balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ pub async fn account_balance(
account_balance_options.chain_name
))?;

let payment_setup = PaymentSetup::new(config, vec![], true, false, false, 1, 1, false, false)?;
let payment_setup =
PaymentSetup::new(config, vec![], true, false, false, 1, 1, 1, false, false)?;

let web3 = payment_setup.get_provider(chain_cfg.chain_id)?;

Expand Down
1 change: 1 addition & 0 deletions crates/erc20_payment_lib_test/src/config_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub async fn create_default_config_setup(proxy_url_base: &str, proxy_key: &str)
chain: chain_map,
engine: Engine {
process_interval: 1,
process_interval_after_error: 1,
gather_interval: 1,
automatic_recover: false,
gather_at_start: false,
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ async fn main_internal() -> Result<(), PaymentError> {
log::info!("Scanning blockchain {}", scan_blockchain_options.chain_name);

let payment_setup =
PaymentSetup::new(&config, vec![], true, false, false, 1, 1, false, false)?;
PaymentSetup::new(&config, vec![], true, false, false, 1, 1, 1, false, false)?;
let chain_cfg = config
.chain
.get(&scan_blockchain_options.chain_name)
Expand Down

0 comments on commit d70b1ca

Please sign in to comment.