forked from onlydustxyz/marketplace-frontend
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
36263e3
commit d1013d8
Showing
5 changed files
with
65 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use anyhow::Result; | ||
use async_trait::async_trait; | ||
use rocket::http::hyper::body::HttpBody; | ||
use tokio::sync::mpsc; | ||
use tokio_cron_scheduler::{Job, JobScheduler, OnJobNotification}; | ||
|
||
#[async_trait::async_trait] | ||
pub trait Runnable { | ||
async fn run(&self) -> Result<()>; | ||
} | ||
|
||
#[async_trait] | ||
impl Runnable for Job { | ||
async fn run(&self) -> Result<()> { | ||
let mut job = self.clone(); | ||
let mut scheduler = JobScheduler::new().await?; | ||
let (tx, mut rx) = mpsc::unbounded_channel(); | ||
|
||
let on_job_done: Box<OnJobNotification> = Box::new(move |_, _, _| { | ||
let cloned_tx = tx.clone(); | ||
Box::pin(async move { | ||
cloned_tx.clone().send(()).unwrap(); | ||
}) | ||
}); | ||
|
||
job.on_done_notification_add(&scheduler, on_job_done).await?; | ||
|
||
scheduler.add(job).await?; | ||
scheduler.start().await?; | ||
rx.recv().await; // Wait for job completion | ||
scheduler.shutdown().await?; | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters