Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UBERF-8538: Handle backup service errors #7042

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions server/backup/src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.
//

import { Analytics } from '@hcengineering/analytics'
import core, {
BaseWorkspaceInfo,
DOMAIN_TX,
Expand Down Expand Up @@ -81,7 +82,7 @@ class BackupWorker {
`****************************************
backup statistics:`,
{
backuped: stats.processed,
processed: stats.processed,
notChanges: stats.skipped,
failed: stats.failedWorkspaces.length
}
Expand All @@ -91,15 +92,23 @@ class BackupWorker {
async schedule (ctx: MeasureContext): Promise<void> {
console.log('schedule backup with interval', this.config.Interval, 'seconds')
while (!this.canceled) {
const res = await this.backup(ctx)
this.printStats(ctx, res)
try {
const res = await this.backup(ctx, this.config.CoolDown * 1000)
this.printStats(ctx, res)
} catch (err: any) {
Analytics.handleError(err)
ctx.error('error retry in cool down/5', { cooldown: this.config.CoolDown, error: err })
await new Promise<void>((resolve) => setTimeout(resolve, (this.config.CoolDown / 5) * 1000))
continue
}
console.log('cool down', this.config.CoolDown, 'seconds')
await new Promise<void>((resolve) => setTimeout(resolve, this.config.CoolDown * 1000))
}
}

async backup (
ctx: MeasureContext
ctx: MeasureContext,
recheckTimeout: number
): Promise<{ failedWorkspaces: BaseWorkspaceInfo[], processed: number, skipped: number }> {
const workspacesIgnore = new Set(this.config.SkipWorkspaces.split(';'))
ctx.info('skipped workspaces', { workspacesIgnore })
Expand Down Expand Up @@ -135,19 +144,21 @@ class BackupWorker {
workspaces: workspaces.map((it) => it.workspace)
})

return await this.doBackup(ctx, workspaces)
return await this.doBackup(ctx, workspaces, recheckTimeout)
}

async doBackup (
rootCtx: MeasureContext,
workspaces: BaseWorkspaceInfo[]
workspaces: BaseWorkspaceInfo[],
recheckTimeout: number
): Promise<{ failedWorkspaces: BaseWorkspaceInfo[], processed: number, skipped: number }> {
let index = 0

const failedWorkspaces: BaseWorkspaceInfo[] = []
let processed = 0
const startTime = Date.now()
for (const ws of workspaces) {
if (this.canceled) {
if (this.canceled || Date.now() - startTime > recheckTimeout) {
return { failedWorkspaces, processed, skipped: workspaces.length - processed }
}
index++
Expand Down