Skip to content

Commit

Permalink
Renaming process and gather interval
Browse files Browse the repository at this point in the history
  • Loading branch information
scx1332 authored Oct 25, 2023
1 parent 11125b2 commit c273017
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 28 deletions.
8 changes: 4 additions & 4 deletions config-payments.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[engine]
# service sleep is for internal runtime checks
service-sleep = 5
# process sleep is to set how often payments are gathered
gather-sleep = 600
# proces interval (in seconds) is to set how often we want to check for transaction
process-interval = 5
# 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)
gather-at-start = true
automatic-recover = false
Expand Down
4 changes: 2 additions & 2 deletions crates/erc20_payment_lib/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ impl AdditionalOptions {
#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "kebab-case")]
pub struct Engine {
pub service_sleep: u64,
pub gather_sleep: u64,
pub process_interval: u64,
pub gather_interval: u64,
pub gather_at_start: bool,
pub automatic_recover: bool,
}
Expand Down
4 changes: 2 additions & 2 deletions crates/erc20_payment_lib/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,8 @@ impl PaymentRuntime {
!options.keep_running,
options.generate_tx_only,
options.skip_multi_contract_check,
config.engine.service_sleep,
config.engine.gather_sleep,
config.engine.process_interval,
config.engine.gather_interval,
config.engine.gather_at_start,
config.engine.automatic_recover,
)?;
Expand Down
10 changes: 5 additions & 5 deletions crates/erc20_payment_lib/src/sender/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub async fn process_transaction(
) -> Result<(TxDao, ProcessTransactionResult), PaymentError> {
const CHECKS_UNTIL_NOT_FOUND: u64 = 5;

let gather_sleep = Duration::from_secs(payment_setup.gather_sleep);
let gather_interval = Duration::from_secs(payment_setup.gather_interval);

let chain_id = web3_tx_dao.chain_id;
let Some(chain_setup) = payment_setup.chain_setup.get(&chain_id) else {
Expand Down Expand Up @@ -766,9 +766,9 @@ pub async fn process_transaction(
update_tx(conn, web3_tx_dao).await.map_err(err_from!())?;
log::warn!(
"Sleeping for {} seconds (process sleep after transaction send)",
gather_sleep.as_secs()
gather_interval.as_secs()
);
tokio::time::sleep(gather_sleep).await;
tokio::time::sleep(gather_interval).await;
continue;
} else {
//timeout transaction when it is not confirmed after transaction_timeout seconds
Expand Down Expand Up @@ -848,8 +848,8 @@ pub async fn process_transaction(
}
log::warn!(
"Sleeping for {} seconds (process sleep at the end of the loop)",
gather_sleep.as_secs()
gather_interval.as_secs()
);
tokio::time::sleep(gather_sleep).await;
tokio::time::sleep(gather_interval).await;
}
}
13 changes: 9 additions & 4 deletions crates/erc20_payment_lib/src/sender/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,10 @@ pub async fn process_transactions(
}
}

tokio::time::sleep(std::time::Duration::from_secs(payment_setup.service_sleep)).await;
tokio::time::sleep(std::time::Duration::from_secs(
payment_setup.process_interval,
))
.await;
}
Ok(())
}
Expand All @@ -355,7 +358,7 @@ pub async fn service_loop(
signer: impl Signer + Send + Sync + 'static,
event_sender: Option<tokio::sync::mpsc::Sender<DriverEvent>>,
) {
let gather_transactions_interval = payment_setup.gather_sleep as i64;
let gather_transactions_interval = payment_setup.gather_interval as i64;
let mut last_gather_time = if payment_setup.gather_at_start {
chrono::Utc::now() - chrono::Duration::seconds(gather_transactions_interval)
} else {
Expand Down Expand Up @@ -407,8 +410,10 @@ pub async fn service_loop(
Ok(token_transfer_map) => token_transfer_map,
Err(e) => {
log::error!("Error in gather transactions, driver will be stuck, Fix DB to continue {:?}", e);
tokio::time::sleep(std::time::Duration::from_secs(payment_setup.service_sleep))
.await;
tokio::time::sleep(std::time::Duration::from_secs(
payment_setup.process_interval,
))
.await;
continue;
}
};
Expand Down
5 changes: 4 additions & 1 deletion crates/erc20_payment_lib/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ pub async fn confirm_loop(
payment_setup: &PaymentSetup,
) {
loop {
tokio::time::sleep(std::time::Duration::from_secs(payment_setup.service_sleep)).await;
tokio::time::sleep(std::time::Duration::from_secs(
payment_setup.process_interval,
))
.await;
}
}
12 changes: 6 additions & 6 deletions crates/erc20_payment_lib/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ pub struct PaymentSetup {
pub finish_when_done: bool,
pub generate_tx_only: bool,
pub skip_multi_contract_check: bool,
pub service_sleep: u64,
pub gather_sleep: u64,
pub process_interval: u64,
pub gather_interval: u64,
pub gather_at_start: bool,
pub automatic_recover: bool,
pub contract_use_direct_method: bool,
Expand All @@ -78,8 +78,8 @@ impl PaymentSetup {
finish_when_done: bool,
generate_txs_only: bool,
skip_multi_contract_check: bool,
service_sleep: u64,
gather_sleep: u64,
process_interval: u64,
gather_interval: u64,
gather_at_start: bool,
automatic_recover: bool,
) -> Result<Self, PaymentError> {
Expand All @@ -90,8 +90,8 @@ impl PaymentSetup {
finish_when_done,
generate_tx_only: generate_txs_only,
skip_multi_contract_check,
service_sleep,
gather_sleep,
process_interval,
gather_interval,
gather_at_start,
automatic_recover,
contract_use_direct_method: false,
Expand Down
4 changes: 2 additions & 2 deletions crates/erc20_payment_lib_test/src/config_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ pub async fn create_default_config_setup(proxy_url_base: &str, proxy_key: &str)
Config {
chain: chain_map,
engine: Engine {
service_sleep: 1,
gather_sleep: 1,
process_interval: 1,
gather_interval: 1,
automatic_recover: false,
gather_at_start: false,
},
Expand Down
4 changes: 2 additions & 2 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ pub struct RunOptions {
help = "Sleep time between service loops in seconds",
default_value = "10"
)]
pub service_sleep: u64,
pub process_interval: u64,

#[structopt(
long = "process-sleep",
help = "Sleep time between process loops in seconds",
default_value = "10"
)]
pub gather_sleep: u64,
pub gather_interval: u64,

#[structopt(long = "http", help = "Enable http server")]
pub http: bool,
Expand Down

0 comments on commit c273017

Please sign in to comment.