Skip to content

Commit

Permalink
fixed sunset jobs not being removed
Browse files Browse the repository at this point in the history
  • Loading branch information
ana_rchy committed May 19, 2024
1 parent ab74126 commit 5a9f6ec
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/jobs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ pub async fn init_jobs(
#[allow(dead_code)]
const TESTING_CHANNEL_ID: u64 = 1235087573421133824;
let http = client.http.clone();


// arc my beloved
let sunset_job_id: Arc<Mutex<Uuid>> = Default::default();
let evening_bag = Arc::new(Mutex::new(EVENING_MOTD.to_vec()));
let night_bag = Arc::new(Mutex::new(NIGHT_MOTD.to_vec()));
Expand Down Expand Up @@ -77,11 +78,17 @@ pub async fn init_jobs(
let evening_bag = evening_bag.clone();

Box::pin(async move {
let _ = sched.remove(&sunset_job_id.lock().unwrap());
// drop lock before sunset_job_id is used again
// otherwise youre tryna use it while its locked
let id = { *sunset_job_id.lock().unwrap() };

let _ = sched.remove(&id).await;

let job =
create_sunset_job(http, GENERAL_CHANNEL_ID, evening_bag.clone()).await;
*sunset_job_id.lock().unwrap() = sched.add(job).await.unwrap();
let new_id = sched.add(job).await.unwrap();
// can be done without braces but better for consistency
{ *sunset_job_id.lock().unwrap() = new_id; }
})
}))
.build()
Expand Down

0 comments on commit 5a9f6ec

Please sign in to comment.