Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Meet a issue when I add the notification handler to Job #32

Open
longzou opened this issue Mar 7, 2024 · 1 comment
Open

Meet a issue when I add the notification handler to Job #32

longzou opened this issue Mar 7, 2024 · 1 comment

Comments

@longzou
Copy link

longzou commented Mar 7, 2024

When I create a new Job for shared Scheduler, the job could not add notication handler.

let mut jobsch = get_scheduler().clone();
jobsch.shutdown().await?;
let job = Job::new_repeated_async(Duration::from_millis(100u64), run)?;
// job.on_done_notification_add(&jobsch, async move |_, _, |{});
log::info!("Do add a job notification {}", jobsch.inited.read().await);
// below code will locked this thread
match job.on_notifications_add(&jobsch, Box::new(|job_id, notification_id, type_of_notification| {
Box::pin(async move {
println!("Job {:?} was completed, notification {:?} ran ({:?})", job_id, notification_id, type_of_notification);
})
}), vec![tokio_cron_scheduler::JobNotification::Done]).await {
Ok(
) => {},
Err(err) => {
log::info!("add notic failed {}", err);
},
}
log::info!("Do add a job into scheduler"); // this code will not be reached.
get_scheduler().add(job).await

@longzou
Copy link
Author

longzou commented Mar 8, 2024

I found the code in NotificationCreator::add,

        tokio::spawn(async move {
            tokio::spawn(async move {
                // TODO can maybe not use RwLock
                if let Err(_e) = create_tx.send((data, Arc::new(RwLock::new(run)))) {
                    error!("Error sending notification data");
                }
            });
           ....
         });

Should the two tokio::spawn calling be using .await?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant