Skip to content

Commit

Permalink
refactor(webserver): make macro for writing to stderr and warn! at th…
Browse files Browse the repository at this point in the history
…e same time (#2007)
  • Loading branch information
boxbeam authored Apr 29, 2024
1 parent b1184a4 commit 66f7c12
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
16 changes: 7 additions & 9 deletions ee/tabby-webserver/src/cron/db/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use octocrab::{models::Repository, GitHubError, Octocrab};
use crate::{
cron::controller::JobContext,
schema::repository::{GithubRepositoryProvider, GithubRepositoryService},
warn_stderr,
};

pub async fn refresh_all_repositories(
Expand Down Expand Up @@ -49,18 +50,15 @@ async fn refresh_repositories_for_provider(
service
.update_provider_status(provider.id.clone(), false)
.await?;
context
.stderr_writeline(format!(
"GitHub credentials for provider {} are expired or invalid",
provider.display_name
))
.await;
warn_stderr!(
context,
"GitHub credentials for provider {} are expired or invalid",
provider.display_name
);
return Err(source.into());
}
Err(e) => {
context
.stderr_writeline(format!("Failed to fetch repositories from github: {}", e))
.await;
warn_stderr!(context, "Failed to fetch repositories from github: {e}");
return Err(e.into());
}
};
Expand Down
16 changes: 7 additions & 9 deletions ee/tabby-webserver/src/cron/db/gitlab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use serde::Deserialize;
use crate::{
cron::controller::JobContext,
schema::repository::{GitlabRepositoryProvider, GitlabRepositoryService},
warn_stderr,
};

pub async fn refresh_all_repositories(
Expand Down Expand Up @@ -50,18 +51,15 @@ async fn refresh_repositories_for_provider(
service
.update_provider_status(provider.id.clone(), false)
.await?;
context
.stderr_writeline(format!(
"GitLab credentials for provider {} are expired or invalid",
provider.display_name
))
.await;
warn_stderr!(
context,
"GitLab credentials for provider {} are expired or invalid",
provider.display_name
);
return Err(e.into());
}
Err(e) => {
context
.stderr_writeline(format!("Failed to fetch repositories from gitlab: {e}"))
.await;
warn_stderr!(context, "Failed to fetch repositories from gitlab: {e}");
return Err(e.into());
}
};
Expand Down
8 changes: 8 additions & 0 deletions ee/tabby-webserver/src/cron/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ use crate::schema::{
worker::WorkerService,
};

#[macro_export]
macro_rules! warn_stderr {
($ctx:expr, $($params:tt)+) => {
tracing::warn!($($params)+);
$ctx.stderr_writeline(format!($($params)+)).await;
}
}

pub async fn run_cron(
auth: Arc<dyn AuthenticationService>,
job: Arc<dyn JobService>,
Expand Down

0 comments on commit 66f7c12

Please sign in to comment.