Queue Dates + Warnings, some cleanup (#549)

* Queue Dates + Warnings, some cleanup

* Fix ping

* Fix repeated discord messaging

* Fix compile error + run fmt
This commit is contained in:
Geometrically
2023-03-14 14:48:46 -07:00
committed by GitHub
parent 150329dd4a
commit 630a71c46c
23 changed files with 701 additions and 2212 deletions

View File

@@ -7,6 +7,7 @@ use crate::ratelimit::middleware::RateLimiter;
use crate::util::env::{parse_strings_from_var, parse_var};
use actix_cors::Cors;
use actix_web::{web, App, HttpServer};
use chrono::{DateTime, Utc};
use env_logger::Env;
use log::{error, info, warn};
use search::indexing::index_projects;
@@ -201,6 +202,74 @@ async fn main() -> std::io::Result<()> {
}
});
// Reminding moderators to review projects which have been in the queue longer than 24hr
let pool_ref = pool.clone();
let webhook_message_sent = Arc::new(Mutex::new(Vec::<(
database::models::ProjectId,
DateTime<Utc>,
)>::new()));
scheduler.run(std::time::Duration::from_secs(10 * 60), move || {
let pool_ref = pool_ref.clone();
let webhook_message_sent_ref = webhook_message_sent.clone();
info!("Checking reviewed projects submitted more than 24hrs ago");
async move {
let do_steps = async {
use futures::TryStreamExt;
let project_ids = sqlx::query!(
"
SELECT id FROM mods
WHERE status = $1 AND queued < NOW() - INTERVAL '1 day'
ORDER BY updated ASC
",
crate::models::projects::ProjectStatus::Processing.as_str(),
)
.fetch_many(&pool_ref)
.try_filter_map(|e| async {
Ok(e.right().map(|m| database::models::ProjectId(m.id)))
})
.try_collect::<Vec<database::models::ProjectId>>()
.await?;
let mut webhook_message_sent_ref = webhook_message_sent_ref.lock().await;
webhook_message_sent_ref.retain(|x| Utc::now() - x.1 > chrono::Duration::hours(12));
for project in project_ids {
if webhook_message_sent_ref.iter().any(|x| x.0 == project) { continue; }
if let Ok(webhook_url) =
dotenvy::var("MODERATION_DISCORD_WEBHOOK")
{
util::webhook::send_discord_webhook(
project.into(),
&pool_ref,
webhook_url,
Some("<@&783155186491195394> This project has been in the queue for over 24 hours!".to_string()),
)
.await
.ok();
webhook_message_sent_ref.push((project, Utc::now()));
}
}
Ok::<(), crate::routes::ApiError>(())
};
if let Err(e) = do_steps.await {
warn!(
"Checking reviewed projects submitted more than 24hrs ago failed: {:?}",
e
);
}
info!("Finished checking reviewed projects submitted more than 24hrs ago");
}
});
scheduler::schedule_versions(&mut scheduler, pool.clone());
let download_queue = Arc::new(DownloadQueue::new());