Skip to content

Commit

Permalink
fix: prevent early return of cron loop (#1031)
Browse files Browse the repository at this point in the history
  • Loading branch information
darknight authored and wsxiaoys committed Dec 14, 2023
1 parent cf89342 commit ac7152c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
15 changes: 6 additions & 9 deletions ee/tabby-webserver/src/schema/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,18 @@ pub fn validate_jwt(token: &str) -> jwt::errors::Result<JWTPayload> {
}

fn jwt_token_secret() -> String {
let jwt_secret = match std::env::var("TABBY_WEBSERVER_JWT_TOKEN_SECRET") {
Ok(x) => x,
Err(_) => {
eprintln!("
let jwt_secret = std::env::var("TABBY_WEBSERVER_JWT_TOKEN_SECRET").unwrap_or_else(|_| {
eprintln!("
\x1b[93;1mJWT secret is not set\x1b[0m
Tabby server will generate a one-time (non-persisted) JWT secret for the current process.
Please set the \x1b[94mTABBY_WEBSERVER_JWT_TOKEN_SECRET\x1b[0m environment variable for production usage.
"
);
Uuid::new_v4().to_string()
}
};
);
Uuid::new_v4().to_string()
});

if uuid::Uuid::parse_str(&jwt_secret).is_err() {
if Uuid::parse_str(&jwt_secret).is_err() {
warn!("JWT token secret needs to be in standard uuid format to ensure its security, you might generate one at https://www.uuidgenerator.net");
std::process::exit(1)
}
Expand Down
8 changes: 4 additions & 4 deletions ee/tabby-webserver/src/service/cron.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::time::Duration;

use anyhow::Result;
use tokio_cron_scheduler::{Job, JobScheduler};
use tracing::{error, warn};
use tracing::error;

use crate::service::db::DbConn;

Expand Down Expand Up @@ -32,7 +32,7 @@ async fn new_refresh_token_job(db_conn: DbConn) -> Result<Job> {

pub fn run_offline_job(db_conn: DbConn) {
tokio::spawn(async move {
let Ok(job) = new_refresh_token_job(db_conn.clone()).await else {
let Ok(job) = new_refresh_token_job(db_conn).await else {
error!("failed to create db job");
return;
};
Expand All @@ -48,8 +48,8 @@ pub fn run_offline_job(db_conn: DbConn) {
tokio::time::sleep(duration).await;
}
Ok(None) => {
warn!("no job available, exit scheduler");
return;
// wait until scheduler increases jobs' tick
tokio::time::sleep(Duration::from_millis(500)).await;
}
Err(e) => {
error!("failed to get job sleep time: {}, re-try in 1 second", e);
Expand Down

0 comments on commit ac7152c

Please sign in to comment.