Skip to content

Commit c51495d

Browse files
authoredMar 28, 2025··
chore(background-job): adjust log path to jobs dir and hashed id (#4081)
* docs(backup): add guide to backup background jobs dir * docs(backup): apply review to use new job path * chore(background-job): use jobs and hashed id as job path * chore: use updated path
1 parent 9ce8383 commit c51495d

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed
 

‎ee/tabby-webserver/src/path.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ pub fn db_file() -> PathBuf {
1616

1717
pub fn background_jobs_dir() -> PathBuf {
1818
if cfg!(feature = "prod") {
19-
tabby_ee_root().join("background-jobs")
19+
tabby_ee_root().join("jobs")
2020
} else {
21-
tabby_ee_root().join("dev-background-jobs")
21+
tabby_ee_root().join("dev-jobs")
2222
}
2323
}

‎ee/tabby-webserver/src/service/background_job/helper/logger.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::{fs::File, io::Write};
22

33
use anyhow::Result;
44
use tabby_db::DbConn;
5+
use tabby_schema::AsID;
56
use tracing::warn;
67

78
use crate::path::background_jobs_dir;
@@ -37,7 +38,7 @@ struct DbTarget {
3738

3839
impl DbTarget {
3940
fn new(db: DbConn, id: i64) -> Result<(Self, tokio::task::JoinHandle<()>)> {
40-
let job_dir = background_jobs_dir().join(format!("{}", id));
41+
let job_dir = background_jobs_dir().join(id.as_id().to_string());
4142
std::fs::create_dir_all(&job_dir)?;
4243
let stdout_path = job_dir.join("stdout.log");
4344
let file = File::create(&stdout_path)?;

‎ee/tabby-webserver/src/service/job.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl JobService for JobControllerImpl {
7171
for job in jobs.iter_mut() {
7272
if job.stdout.is_empty() {
7373
// it is possible that the job is starting to run and the stdout is not yet available
74-
if let Ok(stdout) = self.read_job_stdout(job.id.as_rowid()?).await {
74+
if let Ok(stdout) = self.read_job_stdout(job.id.clone().to_string()).await {
7575
job.stdout = stdout;
7676
}
7777
}
@@ -92,7 +92,7 @@ impl JobService for JobControllerImpl {
9292

9393
if job_run.stdout.is_empty() {
9494
// it is possible that the job is starting to run and the stdout is not yet available
95-
if let Ok(stdout) = self.read_job_stdout(job_run.id.as_rowid()?).await {
95+
if let Ok(stdout) = self.read_job_stdout(job_run.id.to_string()).await {
9696
job_run.stdout = stdout;
9797
}
9898
}
@@ -114,10 +114,8 @@ impl JobService for JobControllerImpl {
114114
}
115115

116116
impl JobControllerImpl {
117-
async fn read_job_stdout(&self, id: i64) -> Result<String> {
118-
let log_file = background_jobs_dir()
119-
.join(format!("{}", id))
120-
.join("stdout.log");
117+
async fn read_job_stdout(&self, id: String) -> Result<String> {
118+
let log_file = background_jobs_dir().join(id).join("stdout.log");
121119

122120
if log_file.exists() {
123121
match read_to_string(log_file).await {

‎website/docs/administration/backup.md

+11
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,15 @@ Tabby stores all event logs in the `~/.tabby/events` directory. These events, st
4545
2023-12-04.json 2023-12-19.json 2024-01-26.json 2024-02-07.json 2024-02-18.json 2024-03-02.json
4646
2023-12-05.json 2023-12-20.json 2024-01-27.json 2024-02-08.json 2024-02-19.json 2024-03-03.json
4747
2023-12-07.json 2023-12-22.json 2024-01-30.json 2024-02-09.json 2024-02-20.json 2024-03-05.json
48+
```
49+
50+
## Background Job Logs Backup
51+
52+
Starting with version v0.27.0, Tabby saves all background job logs in the `~/.tabby/ee/jobs` directory.
53+
To display the logs in the management UI, it is essential to back up this directory.
54+
55+
```
56+
% ls ~/.tabby/ee/jobs
57+
58+
DGJ7Xw JGODZw L1Pp41 nwY59w
4859
```

0 commit comments

Comments
 (0)
Please sign in to comment.