Disable transaction monitor tasks if blockchain integration is disabled

This commit is contained in:
silverpill 2023-04-09 16:41:56 +00:00
parent bd371189a0
commit d2d340158e
2 changed files with 29 additions and 25 deletions

View file

@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Added emoji count check to profile data validator. - Added emoji count check to profile data validator.
- Check mention and link counts when creating post. - Check mention and link counts when creating post.
- Disable transaction monitor tasks if blockchain integration is disabled.
## [1.20.0] - 2023-03-07 ## [1.20.0] - 2023-03-07

View file

@ -11,14 +11,14 @@ use super::periodic_tasks::*;
#[derive(Debug, Eq, Hash, PartialEq)] #[derive(Debug, Eq, Hash, PartialEq)]
enum PeriodicTask { enum PeriodicTask {
EthereumSubscriptionMonitor,
SubscriptionExpirationMonitor,
MoneroPaymentMonitor,
IncomingActivityQueueExecutor, IncomingActivityQueueExecutor,
OutgoingActivityQueueExecutor, OutgoingActivityQueueExecutor,
DeleteExtraneousPosts, DeleteExtraneousPosts,
DeleteEmptyProfiles, DeleteEmptyProfiles,
PruneRemoteEmojis, PruneRemoteEmojis,
SubscriptionExpirationMonitor,
EthereumSubscriptionMonitor,
MoneroPaymentMonitor,
#[cfg(feature = "ethereum-extras")] #[cfg(feature = "ethereum-extras")]
NftMonitor, NftMonitor,
@ -28,14 +28,14 @@ impl PeriodicTask {
/// Returns task period (in seconds) /// Returns task period (in seconds)
fn period(&self) -> i64 { fn period(&self) -> i64 {
match self { match self {
Self::EthereumSubscriptionMonitor => 300,
Self::SubscriptionExpirationMonitor => 300,
Self::MoneroPaymentMonitor => 30,
Self::IncomingActivityQueueExecutor => 5, Self::IncomingActivityQueueExecutor => 5,
Self::OutgoingActivityQueueExecutor => 5, Self::OutgoingActivityQueueExecutor => 5,
Self::DeleteExtraneousPosts => 3600, Self::DeleteExtraneousPosts => 3600,
Self::DeleteEmptyProfiles => 3600, Self::DeleteEmptyProfiles => 3600,
Self::PruneRemoteEmojis => 3600, Self::PruneRemoteEmojis => 3600,
Self::SubscriptionExpirationMonitor => 300,
Self::EthereumSubscriptionMonitor => 300,
Self::MoneroPaymentMonitor => 30,
#[cfg(feature = "ethereum-extras")] #[cfg(feature = "ethereum-extras")]
Self::NftMonitor => 30, Self::NftMonitor => 30,
@ -60,15 +60,10 @@ pub fn run(
) -> () { ) -> () {
tokio::spawn(async move { tokio::spawn(async move {
let mut scheduler_state = HashMap::from([ let mut scheduler_state = HashMap::from([
(PeriodicTask::EthereumSubscriptionMonitor, None),
(PeriodicTask::SubscriptionExpirationMonitor, None),
(PeriodicTask::MoneroPaymentMonitor, None),
(PeriodicTask::IncomingActivityQueueExecutor, None), (PeriodicTask::IncomingActivityQueueExecutor, None),
(PeriodicTask::OutgoingActivityQueueExecutor, None), (PeriodicTask::OutgoingActivityQueueExecutor, None),
(PeriodicTask::PruneRemoteEmojis, None), (PeriodicTask::PruneRemoteEmojis, None),
(PeriodicTask::SubscriptionExpirationMonitor, None),
#[cfg(feature = "ethereum-extras")]
(PeriodicTask::NftMonitor, None),
]); ]);
if config.retention.extraneous_posts.is_some() { if config.retention.extraneous_posts.is_some() {
scheduler_state.insert(PeriodicTask::DeleteExtraneousPosts, None); scheduler_state.insert(PeriodicTask::DeleteExtraneousPosts, None);
@ -76,6 +71,14 @@ pub fn run(
if config.retention.empty_profiles.is_some() { if config.retention.empty_profiles.is_some() {
scheduler_state.insert(PeriodicTask::DeleteEmptyProfiles, None); scheduler_state.insert(PeriodicTask::DeleteEmptyProfiles, None);
}; };
if config.ethereum_config().is_some() {
scheduler_state.insert(PeriodicTask::EthereumSubscriptionMonitor, None);
#[cfg(feature = "ethereum-extras")]
scheduler_state.insert(PeriodicTask::NftMonitor, None);
};
if config.monero_config().is_some() {
scheduler_state.insert(PeriodicTask::MoneroPaymentMonitor, None);
};
let mut interval = tokio::time::interval(Duration::from_secs(5)); let mut interval = tokio::time::interval(Duration::from_secs(5));
loop { loop {
@ -86,19 +89,6 @@ pub fn run(
continue; continue;
}; };
let task_result = match task { let task_result = match task {
PeriodicTask::EthereumSubscriptionMonitor => {
ethereum_subscription_monitor(
&config,
maybe_ethereum_blockchain.as_mut(),
&db_pool,
).await
},
PeriodicTask::SubscriptionExpirationMonitor => {
subscription_expiration_monitor(&config, &db_pool).await
},
PeriodicTask::MoneroPaymentMonitor => {
monero_payment_monitor(&config, &db_pool).await
},
PeriodicTask::IncomingActivityQueueExecutor => { PeriodicTask::IncomingActivityQueueExecutor => {
incoming_activity_queue_executor(&config, &db_pool).await incoming_activity_queue_executor(&config, &db_pool).await
}, },
@ -114,6 +104,16 @@ pub fn run(
PeriodicTask::PruneRemoteEmojis => { PeriodicTask::PruneRemoteEmojis => {
prune_remote_emojis(&config, &db_pool).await prune_remote_emojis(&config, &db_pool).await
}, },
PeriodicTask::SubscriptionExpirationMonitor => {
subscription_expiration_monitor(&config, &db_pool).await
},
PeriodicTask::EthereumSubscriptionMonitor => {
ethereum_subscription_monitor(
&config,
maybe_ethereum_blockchain.as_mut(),
&db_pool,
).await
},
#[cfg(feature = "ethereum-extras")] #[cfg(feature = "ethereum-extras")]
PeriodicTask::NftMonitor => { PeriodicTask::NftMonitor => {
nft_monitor( nft_monitor(
@ -121,6 +121,9 @@ pub fn run(
&db_pool, &db_pool,
).await ).await
}, },
PeriodicTask::MoneroPaymentMonitor => {
monero_payment_monitor(&config, &db_pool).await
},
}; };
task_result.unwrap_or_else(|err| { task_result.unwrap_or_else(|err| {
log::error!("{:?}: {}", task, err); log::error!("{:?}: {}", task, err);