fix: Optimize backup logic for cronjob (#10308)

This commit is contained in:
ssongliu 2025-09-09 12:20:43 +08:00 committed by GitHub
parent f682f07dbc
commit 08a07214ef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 22 additions and 3 deletions

View file

@ -27,7 +27,8 @@ import (
func (u *CronjobService) handleApp(cronjob model.Cronjob, startTime time.Time, taskItem *task.Task) error {
apps := loadAppsForJob(cronjob)
if len(apps) == 0 {
return errors.New("no such app in database!")
addSkipTask("App", taskItem)
return nil
}
accountMap := NewBackupClientMap(strings.Split(cronjob.SourceAccountIDs, ","))
if !accountMap[fmt.Sprintf("%d", cronjob.DownloadAccountID)].isOk {
@ -83,7 +84,8 @@ func (u *CronjobService) handleApp(cronjob model.Cronjob, startTime time.Time, t
func (u *CronjobService) handleWebsite(cronjob model.Cronjob, startTime time.Time, taskItem *task.Task) error {
webs := loadWebsForJob(cronjob)
if len(webs) == 0 {
return errors.New("no such website in database!")
addSkipTask("Website", taskItem)
return nil
}
accountMap := NewBackupClientMap(strings.Split(cronjob.SourceAccountIDs, ","))
if !accountMap[fmt.Sprintf("%d", cronjob.DownloadAccountID)].isOk {
@ -140,7 +142,8 @@ func (u *CronjobService) handleWebsite(cronjob model.Cronjob, startTime time.Tim
func (u *CronjobService) handleDatabase(cronjob model.Cronjob, startTime time.Time, taskItem *task.Task) error {
dbs := loadDbsForJob(cronjob)
if len(dbs) == 0 {
return errors.New("no such db in database!")
addSkipTask("Database", taskItem)
return nil
}
accountMap := NewBackupClientMap(strings.Split(cronjob.SourceAccountIDs, ","))
if !accountMap[fmt.Sprintf("%d", cronjob.DownloadAccountID)].isOk {
@ -372,6 +375,13 @@ type DatabaseHelper struct {
Name string
}
func addSkipTask(source string, taskItem *task.Task) {
taskItem.AddSubTask(task.GetTaskName(i18n.GetMsgByKey(source), task.TaskBackup, task.TaskScopeCronjob), func(task *task.Task) error {
taskItem.Log(i18n.GetMsgByKey("NoSuchResource"))
return nil
}, nil)
}
func loadDbsForJob(cronjob model.Cronjob) []DatabaseHelper {
var dbs []DatabaseHelper
if cronjob.DBName == "all" {

View file

@ -235,6 +235,7 @@ IgnoreBackupErr: "Backup failed, error: {{ .detail }}, ignoring this error..."
IgnoreUploadErr: "Upload failed, error: {{ .detail }}, ignoring this error..."
LoadBackupFailed: "Failed to get backup account connection, error: {{ .detail }}"
InExecuting: "The current task is being executed, please do not repeat the execution!"
NoSuchResource: "No backup content found in the database, skipping..."
#toolbox
ErrNotExistUser: 'The current user does not exist, please modify and try again!'

View file

@ -235,6 +235,7 @@ IgnoreBackupErr: "バックアップ失敗、エラー: {{ .detail }}、この
IgnoreUploadErr: "アップロード失敗、エラー: {{ .detail }}、このエラーを無視します..."
LoadBackupFailed: "バックアップアカウントの接続取得に失敗、エラー: {{ .detail }}"
InExecuting: "現在のタスクは実行中です。重複して実行しないでください!"
NoSuchResource: "データベースにバックアップ内容が見つかりませんでした。スキップします..."
#toolbox
ErrNotExistUser: '現在のユーザーは存在しません。変更してもう一度お試しください。'

View file

@ -235,6 +235,7 @@ IgnoreBackupErr: "백업 실패, 오류: {{ .detail }}, 이 오류를 무시합
IgnoreUploadErr: "업로드 실패, 오류: {{ .detail }}, 이 오류를 무시합니다..."
LoadBackupFailed: "백업 계정 연결 획득 실패, 오류: {{ .detail }}"
InExecuting: "현재 작업이 실행 중입니다. 중복 실행하지 마세요!"
NoSuchResource: "데이터베이스에서 백업 내용을 찾을 수 없어 건너뜁니다..."
#도구상자
ErrNotExistUser: '현재 사용자가 존재하지 않습니다. 수정한 후 다시 시도하세요!'

View file

@ -235,6 +235,7 @@ IgnoreBackupErr: "Sandaran gagal, ralat: {{ .detail }}, abaikan ralat ini..."
IgnoreUploadErr: "Muat naik gagal, ralat: {{ .detail }}, abaikan ralat ini..."
LoadBackupFailed: "Gagal mendapatkan sambungan akaun sandaran, ralat: {{ .detail }}"
InExecuting: "Tugas semasa sedang dilaksanakan, jangan ulangi pelaksanaan!"
NoSuchResource: "Tiada kandungan sandaran ditemui dalam pangkalan data, dilangkau..."
#kotak alat
ErrNotExistUser: 'Pengguna semasa tidak wujud, sila ubah suai dan cuba lagi!'

View file

@ -235,6 +235,7 @@ IgnoreBackupErr: "Backup falhou, erro: {{ .detail }}, ignorando este erro..."
IgnoreUploadErr: "Upload falhou, erro: {{ .detail }}, ignorando este erro..."
LoadBackupFailed: "Falha ao obter conexão da conta de backup, erro: {{ .detail }}"
InExecuting: "A tarefa atual está sendo executada, não repita a execução!"
NoSuchResource: "Nenhum conteúdo de backup encontrado no banco de dados, ignorando..."
#caixa de ferramentas
ErrNotExistUser: 'O usuário atual não existe, modifique e tente novamente!'

View file

@ -235,6 +235,7 @@ IgnoreBackupErr: "Ошибка резервного копирования: {{ .
IgnoreUploadErr: "Ошибка загрузки: {{ .detail }}, игнорируем эту ошибку..."
LoadBackupFailed: "Не удалось получить подключение к учетной записи резервной копии, ошибка: {{ .detail }}"
InExecuting: "Текущая задача выполняется, не повторяйте выполнение!"
NoSuchResource: "В базе данных не найдено содержимое резервной копии, пропускаем..."
#ящик для инструментов
ErrNotExistUser: 'Текущий пользователь не существует, измените его и повторите попытку!'

View file

@ -236,6 +236,7 @@ IgnoreBackupErr: "Yedekleme başarısız, hata: {{ .detail }}, bu hata yoksayıl
IgnoreUploadErr: "Yükleme başarısız, hata: {{ .detail }}, bu hata yoksayılıyor..."
LoadBackupFailed: "Yedek hesap bağlantısı alınamadı, hata: {{ .detail }}"
InExecuting: "Mevcut görev yürütülüyor, lütfen tekrar yürütmeyin!"
NoSuchResource: "Veritabanında yedek içeriği bulunamadı, atlanıyor..."
#toolbox
ErrNotExistUser: 'Mevcut kullanıcı mevcut değil, lütfen değiştirin ve tekrar deneyin!'

View file

@ -234,6 +234,7 @@ IgnoreBackupErr: "備份失敗,錯誤:{{ .detail }},忽略本次錯誤..."
IgnoreUploadErr: "上傳失敗,錯誤:{{ .detail }},忽略本次錯誤..."
LoadBackupFailed: "獲取備份帳號連接失敗,錯誤:{{ .detail }}"
InExecuting: "當前任務正在執行中,請勿重複執行!"
NoSuchResource: "資料庫中未能查詢到備份內容,跳過..."
#toolbox
ErrNotExistUser: '目前使用者不存在,請修改後重試!'

View file

@ -234,6 +234,7 @@ IgnoreBackupErr: "备份失败,错误:{{ .detail }},忽略本次错误..."
IgnoreUploadErr: "上传失败,错误:{{ .detail }},忽略本次错误..."
LoadBackupFailed: "获取备份账号连接失败,错误:{{ .detail }}"
InExecuting: "当前任务正在执行中,请勿重复执行!"
NoSuchResource: "数据库中未能查询到备份内容,跳过..."
#toolbox
ErrNotExistUser: "当前用户不存在,请修改后重试!"