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

Xo tasks @xo/backups #8012

Open
wants to merge 5 commits into
base: backup-XO-Tasks
Choose a base branch
from
Open

Xo tasks @xo/backups #8012

wants to merge 5 commits into from

Conversation

b-Nollet
Copy link
Contributor

Description

Replacing backup tasks by tasks from @vates/task in @xen-orchestra/backups.

Merge this to branch backup-XO-Tasks instead of master, as it must not be merged before further changes are made.

Checklist

  • Commit
    • Title follows commit conventions
    • Reference the relevant issue (Fixes #007, See xoa-support#42, See https://...)
    • If bug fix, add Introduced by
  • Changelog
    • If visible by XOA users, add changelog entry
    • Update "Packages to release" in CHANGELOG.unreleased.md
  • PR
    • If UI changes, add screenshots
    • If not finished or not tested, open as Draft

Review process

This 2-passes review process aims to:

  • develop skills of junior reviewers
  • limit the workload for senior reviewers
  • limit the number of unnecessary changes by the author
  1. The author creates a PR.
  2. Review process:
    1. The author assigns the junior reviewer.
    2. The junior reviewer conducts their review:
      • Resolves their comments if they are addressed.
      • Adds comments if necessary or approves the PR.
    3. The junior reviewer assigns the senior reviewer.
    4. The senior reviewer conducts their review:
      • If there are no unresolved comments on the PR → merge.
      • Otherwise, we continue with 3.
  3. The author responds to comments and/or makes corrections, and we go back to 2.

Notes:

  1. The author can request a review at any time, even if the PR is still a Draft.
  2. In theory, there should not be more than one reviewer at a time.
  3. The author should not make any changes:
    • When a reviewer is assigned.
    • Between the junior and senior reviews.

Copy link
Member

@MathieuRA MathieuRA left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if this is normal, since the work will be split into multiple PRs, but log.tasks doesn't exist anymore, and this breaks the UI.

{
  "data": {
    "mode": "delta",
    "reportWhen": "failure"
  },
  "id": "1727783877606",
  "jobId": "d78a6445-1c59-4932-9851-d6c642e46c21",
  "jobName": "8.2 non smart mode",
  "message": "backup",
  "scheduleId": "464e7258-3559-4716-aa3e-743c85bd89c9",
  "start": 1727783877606,
  "status": "success",
  "end": 1727783897166
}

Capture d’écran de 2024-10-01 13-58-38

Copy link
Collaborator

@fbeauchamp fbeauchamp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please rework the retry task handling

)
)
}

if (job.xoMetadata !== undefined && settings.retentionXoMetadata !== 0) {
promises.push(
runTask(
Task.run(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we use runInside here to ensure we don't lose an error ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only difference using runInside would make is that the task would stay pending if it doesn't have an error, so it's not a solution.
If we want the backup to fail when one subtask fails, we would have to remove the .catch(noop), but it would need some testing as it may have other consequences.

@b-Nollet
Copy link
Contributor Author

I don't know if this is normal, since the work will be split into multiple PRs, but log.tasks doesn't exist anymore, and this breaks the UI.

{
  "data": {
    "mode": "delta",
    "reportWhen": "failure"
  },
  "id": "1727783877606",
  "jobId": "d78a6445-1c59-4932-9851-d6c642e46c21",
  "jobName": "8.2 non smart mode",
  "message": "backup",
  "scheduleId": "464e7258-3559-4716-aa3e-743c85bd89c9",
  "start": 1727783877606,
  "status": "success",
  "end": 1727783897166
}

Capture d’écran de 2024-10-01 13-58-38

Yes, backup tasks and vates tasks handle logs differently, it will be dealt with later

@@ -110,22 +110,32 @@ export const VmsRemote = class RemoteVmsBackupRunner extends Abstract {
taskByVmId[vmUuid] = new Task(taskStart)
}
const task = taskByVmId[vmUuid]
// error has to be caught in the taskto prevent in failure, but handled outside the task to execute another task.run()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// error has to be caught in the taskto prevent in failure, but handled outside the task to execute another task.run()
// error has to be caught in the task to prevent in failure, but handled outside the task to execute another task.run()

})
)
.then(result => {
if (taskError) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (taskError) {
if (taskError !== undefined) {

Comment on lines +116 to +138
.runInside(async () =>
vmBackup.run().catch(error => {
taskError = error
})
)
.then(result => {
if (taskError) {
if (isLastRun) {
throw error
// ending the task with error
return task.run(() => {
throw taskError
})
} else {
Task.warning(`Retry the VM mirror backup due to an error`, {
// don't end the task
task.warning(`Retry the VM mirror backup due to an error`, {
attempt: nTriesByVmId[vmUuid],
error: error.message,
error: taskError.message,
})
queue.add(vmUuid)
}
} else {
// ending the task with success
task.run(() => result)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid nested if/else, i suggest something like that:

// NOT TESTED
return task.runInside(async () => {
  let result
  try {
    result = await vmBackup.run()
  } catch (error) {
    taskError = error
  }

  if (taskError === undefined) {
    return task.run(() => result)
  }

  if (isLastRun) {
    return task.run(() => {
      throw taskError
    })
  }

  task.warning(`Retry the VM mirror backup due to an error`, {
    attempt: nTriesByVmId[vmUuid],
    error: taskError.message,
  })
  queue.add(vmUuid)
})

@@ -110,22 +110,32 @@ export const VmsRemote = class RemoteVmsBackupRunner extends Abstract {
taskByVmId[vmUuid] = new Task(taskStart)
}
const task = taskByVmId[vmUuid]
// error has to be caught in the taskto prevent in failure, but handled outside the task to execute another task.run()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// error has to be caught in the taskto prevent in failure, but handled outside the task to execute another task.run()
// error has to be caught in the taskto prevent its failure, but handled outside the task to execute another task.run()

}

const task = getVmTask()
// error has to be caught in the taskto prevent in failure, but handled outside the task to execute another task.run()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// error has to be caught in the taskto prevent in failure, but handled outside the task to execute another task.run()
// error has to be caught in the task to prevent its failure, but handled outside the task to execute another task.run()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants