forked from Skynet/discord-bot
feat: moved the update data to the main thread
This commit is contained in:
parent
13eb230754
commit
227db8a741
4 changed files with 21 additions and 77 deletions
22
src/main.rs
22
src/main.rs
|
@ -19,7 +19,8 @@ use serenity::{
|
|||
use skynet_discord_bot::common::database::{db_init, get_server_config, get_server_config_bulk, get_server_member, DataBase};
|
||||
use skynet_discord_bot::common::set_roles::committee::update_committees;
|
||||
use skynet_discord_bot::common::set_roles::{committee, normal};
|
||||
use skynet_discord_bot::common::wolves::committees::Committees;
|
||||
use skynet_discord_bot::common::wolves::cns::get_wolves;
|
||||
use skynet_discord_bot::common::wolves::committees::{get_cns, Committees};
|
||||
use skynet_discord_bot::{get_config, Config};
|
||||
use sqlx::{Pool, Sqlite};
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
|
@ -49,6 +50,25 @@ impl EventHandler for Handler {
|
|||
if !self.is_loop_running.load(Ordering::Relaxed) {
|
||||
// We have to clone the Arc, as it gets moved into the new thread.
|
||||
|
||||
{
|
||||
// This updates all the data, wolves user data and the committees
|
||||
let ctx_task = Arc::clone(&ctx);
|
||||
tokio::spawn(async move {
|
||||
loop {
|
||||
println!("Update - Data - Start");
|
||||
|
||||
// get the data for each individual club/soc
|
||||
get_wolves(&ctx_task).await;
|
||||
|
||||
// get teh data for the clubs/socs committees
|
||||
get_cns(&ctx_task).await;
|
||||
|
||||
println!("Update - Data - End");
|
||||
tokio::time::sleep(Duration::from_secs(60 * 5)).await;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
// this is to update member roles every 5 min
|
||||
let ctx_task = Arc::clone(&ctx);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue