2023-03-07 15:41:20 +00:00
|
|
|
use std::convert::Infallible;
|
2023-03-04 18:07:17 +00:00
|
|
|
use fang::queue::AsyncQueueable;
|
|
|
|
use fang::runnable::AsyncRunnable;
|
2023-03-05 00:19:35 +00:00
|
|
|
use fang::errors::FrangoError;
|
2022-07-31 13:32:37 +00:00
|
|
|
use std::time::Duration;
|
2023-03-05 00:19:35 +00:00
|
|
|
use async_trait::async_trait;
|
|
|
|
use serde::{Serialize, Deserialize};
|
2022-07-31 13:32:37 +00:00
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
pub struct MyTask {
|
|
|
|
pub number: u16,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl MyTask {
|
|
|
|
pub fn new(number: u16) -> Self {
|
|
|
|
Self { number }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-04 15:22:53 +00:00
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
pub struct MyFailingTask {
|
|
|
|
pub number: u16,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl MyFailingTask {
|
|
|
|
pub fn new(number: u16) -> Self {
|
|
|
|
Self { number }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-31 13:32:37 +00:00
|
|
|
#[async_trait]
|
|
|
|
#[typetag::serde]
|
|
|
|
impl AsyncRunnable for MyTask {
|
2023-03-07 15:41:20 +00:00
|
|
|
async fn run(&self, queue: &mut dyn AsyncQueueable) -> Result<(), Infallible> {
|
2023-03-04 18:07:17 +00:00
|
|
|
// let new_task = MyTask::new(self.number + 1);
|
|
|
|
// queue
|
|
|
|
// .insert_task(&new_task as &dyn AsyncRunnable)
|
|
|
|
// .await
|
|
|
|
// .unwrap();
|
2022-08-04 15:22:53 +00:00
|
|
|
|
2022-08-03 08:37:53 +00:00
|
|
|
log::info!("the current number is {}", self.number);
|
2022-07-31 13:32:37 +00:00
|
|
|
tokio::time::sleep(Duration::from_secs(3)).await;
|
|
|
|
|
2022-08-04 15:22:53 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[async_trait]
|
|
|
|
#[typetag::serde]
|
|
|
|
impl AsyncRunnable for MyFailingTask {
|
2023-03-05 00:19:35 +00:00
|
|
|
async fn run(&self, queue: &mut dyn AsyncQueueable) -> Result<(), FrangoError> {
|
2023-03-04 18:07:17 +00:00
|
|
|
// let new_task = MyFailingTask::new(self.number + 1);
|
|
|
|
// queue
|
|
|
|
// .insert_task(&new_task as &dyn AsyncRunnable)
|
|
|
|
// .await
|
|
|
|
// .unwrap();
|
2022-07-31 13:32:37 +00:00
|
|
|
|
2022-08-04 15:22:53 +00:00
|
|
|
log::info!("the current number is {}", self.number);
|
|
|
|
tokio::time::sleep(Duration::from_secs(3)).await;
|
|
|
|
|
2023-03-04 18:07:17 +00:00
|
|
|
log::info!("done..");
|
|
|
|
//
|
|
|
|
// let b = true;
|
|
|
|
//
|
|
|
|
// if b {
|
|
|
|
// panic!("Hello!");
|
|
|
|
// } else {
|
|
|
|
// Ok(())
|
|
|
|
// }
|
|
|
|
Ok(())
|
2022-07-31 13:32:37 +00:00
|
|
|
}
|
|
|
|
}
|