Block scheduler if another one is already running
All checks were successful
Build and push container image / build (push) Successful in 12m40s
All checks were successful
Build and push container image / build (push) Successful in 12m40s
This commit is contained in:
parent
483ba390e9
commit
048ce583e8
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -1020,7 +1020,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "kon"
|
name = "kon"
|
||||||
version = "0.3.8"
|
version = "0.3.9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bb8",
|
"bb8",
|
||||||
"bb8-postgres",
|
"bb8-postgres",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "kon"
|
name = "kon"
|
||||||
version = "0.3.8"
|
version = "0.3.9"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
16
src/main.rs
16
src/main.rs
@ -17,7 +17,13 @@ use crate::{
|
|||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
thread::current,
|
thread::current,
|
||||||
sync::Arc
|
sync::{
|
||||||
|
Arc,
|
||||||
|
atomic::{
|
||||||
|
AtomicBool,
|
||||||
|
Ordering
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
use poise::serenity_prelude::{
|
use poise::serenity_prelude::{
|
||||||
builder::{
|
builder::{
|
||||||
@ -35,6 +41,7 @@ use poise::serenity_prelude::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
type Error = Box<dyn std::error::Error + Send + Sync>;
|
type Error = Box<dyn std::error::Error + Send + Sync>;
|
||||||
|
static TASK_RUNNING: AtomicBool = AtomicBool::new(false);
|
||||||
|
|
||||||
async fn on_ready(
|
async fn on_ready(
|
||||||
ctx: &Context,
|
ctx: &Context,
|
||||||
@ -123,6 +130,9 @@ async fn event_processor(
|
|||||||
|
|
||||||
let ctx = Arc::new(ctx.clone());
|
let ctx = Arc::new(ctx.clone());
|
||||||
|
|
||||||
|
if !TASK_RUNNING.load(Ordering::SeqCst) {
|
||||||
|
TASK_RUNNING.store(true, Ordering::SeqCst);
|
||||||
|
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
match internals::tasks::rss::rss(ctx).await {
|
match internals::tasks::rss::rss(ctx).await {
|
||||||
Ok(_) => {},
|
Ok(_) => {},
|
||||||
@ -133,7 +143,11 @@ async fn event_processor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
TASK_RUNNING.store(false, Ordering::SeqCst);
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
println!("TaskScheduler[Main:RSS:Notice]: Another thread is already running this task, ignoring");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user