Skip to content

Commit

Permalink
fix: change in check_job_available func
Browse files Browse the repository at this point in the history
  • Loading branch information
AH-dark committed Jun 25, 2024
1 parent 272497e commit 7b787aa
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/cron.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl<'a> Cron<'a> {

tokio::task::spawn_blocking(|| async move {
// check if the job is available
if node_pool::check_job_available(&np, &job_name).await.is_ok_and(|b| b) {
if np.check_job_available(&job_name).await.is_ok_and(|b| b) {
run();
}
});
Expand Down Expand Up @@ -94,7 +94,7 @@ impl<'a> Cron<'a> {
// spawn the async job
tokio::task::spawn_blocking(|| async move {
// check if the job is available
if node_pool::check_job_available(&np, &job_name)
if np.check_job_available(&job_name)
.await
.is_ok_and(|is_this_node| is_this_node) {
run().await.expect("Failed to run async job, runtime error");
Expand Down
2 changes: 1 addition & 1 deletion src/driver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mod utils;
pub mod redis;

#[async_trait::async_trait]
pub trait Driver: Send + Sync + Debug {
pub(crate) trait Driver: Send + Sync + Debug {
async fn init(&mut self, service_name: String) -> Result<(), Box<dyn std::error::Error>>;
fn node_id(&self) -> String;
async fn get_nodes(&self) -> Result<Vec<String>, Box<dyn std::error::Error>>;
Expand Down
4 changes: 2 additions & 2 deletions src/node_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl NodePool {
}
}

pub async fn init(&mut self) -> Result<(), Error> {
pub(crate) async fn init(&mut self) -> Result<(), Error> {
self.driver.start().await?;
self.node_id = self.driver.node_id();

Expand All @@ -55,7 +55,7 @@ impl NodePool {
}

/// Check if the job should be executed on the current node.
pub async fn check_job_available(&self, job_name: &str) -> Result<bool, Error> {
pub(crate) async fn check_job_available(&self, job_name: &str) -> Result<bool, Error> {
let hash = self.hash.read().await;
match hash.get(&job_name) {
Some(node) => Ok(node == &self.node_id),
Expand Down

0 comments on commit 7b787aa

Please sign in to comment.