Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-75579

Asynchronous restore keeps deleting course/student content

    XMLWordPrintable

Details

    • MOODLE_311_STABLE, MOODLE_400_STABLE, MOODLE_401_STABLE, MOODLE_402_STABLE, MOODLE_403_STABLE
    • MOODLE_402_STABLE, MOODLE_403_STABLE
    • MDL-75579-402
    • MDL-75579-403
    • Hide

      Make sure you don't have any tasks queued in task_adhoc table so it's easy to track the recently added tasks

      PHPUnit

      Verify that all the tests in the below file are pased

      lib/tests/task/adhoc_task_test.php

      Initial setup

      1. Login as admin.
      2. Navigate to Site Administration.
      3. Enable enableasyncbackup setting (Checked).
      4. Create a course called "Test restore course".
      5. Navigate to the created course.
      6. Create some activities (Assign, Quiz...).
      7. Back up that course.
      8. Run php admin/cli/adhoc_task.php --execute to complete the backup process.
      9. Download that backup and save it somewhere.
      10. Apply the Patch_to_test_MDL-75579.patchpatch.

      Testing

      1. Navigate to the created course.
      2. Click on More > Course reuse > Restore.
      3. Upload and restore the downloaded backup.
      4. In the Destination stage, make sure to select Delete the contents of this course and then restore option in "Restore into this course".
      5. Run php admin/cli/adhoc_task.php --execute to complete the restore process.
      6. Verify that you see the below message in the terminal.

        Exception thrown during restore execution, marking job as failed
        error/test-75579-exception

      7. Go to the restored course.
      8. you will have an exception page - refresh the page
      9. Verify that all the course contents are deleted.
      10. Click on More > Course reuse > Restore.
      11. Verify that you do not see a pending restore process.
      12. Go to Site Administration > Server > Adhoc tasks.
      13. Verify that you don't see any failed records with classname is "asynchronous_restore_task"
      Show
      Make sure you don't have any tasks queued in task_adhoc table so it's easy to track the recently added tasks PHPUnit Verify that all the tests in the below file are pased lib/tests/task/adhoc_task_test.php Initial setup Login as admin. Navigate to Site Administration. Enable enableasyncbackup setting (Checked). Create a course called "Test restore course". Navigate to the created course. Create some activities (Assign, Quiz...). Back up that course. Run php admin/cli/adhoc_task.php --execute to complete the backup process. Download that backup and save it somewhere. Apply the Patch_to_test_MDL-75579.patch patch. Testing Navigate to the created course. Click on More > Course reuse > Restore. Upload and restore the downloaded backup. In the Destination stage, make sure to select Delete the contents of this course and then restore  option in "Restore into this course". Run php admin/cli/adhoc_task.php --execute to complete the restore process. Verify that you see the below message in the terminal. Exception thrown during restore execution, marking job as failed error/test-75579-exception Go to the restored course. you will have an exception page - refresh the page Verify that all the course contents are deleted. Click on More > Course reuse > Restore. Verify that you do not see a pending restore process. Go to Site Administration > Server > Adhoc tasks. Verify that you don't see any failed records with classname is "asynchronous_restore_task"
    • 6
    • Team Hedgehog 2023 Review 3, Team Hedgehog 2023 Sprint 4.1, Team Hedgehog 2023 Sprint 4.2, Team Hedgehog 2023 Sprint 4.3, Team Hedgehog 2023 Review 4

    Description

      Steps to replicate

      1. Login as admin.
      2. Navigate to Site administration.
      3. Enable enableasyncbackup setting (Checked).
      4. Create a course called "Test restore course".
      5. Navigate to the created course.
      6. Create some activities (Assign, Quiz...).
      7. Back up that course.
      8. Run php admin/cli/adhoc_task.php --execute to complete the backup process.
      9. Download that backup.
      10. Apply the attached patch.
      11. Upload and restore the downloaded backup.
      12. Make sure to select Delete the contents of this course and then restore option.
      13. Run php admin/cli/adhoc_task.php --execute to complete the restore process.
      14. Verify that all the course content is deleted.
      15. Add a new Assign activity to the course.
      16. Run php admin/cli/adhoc_task.php --execute again.
      17. Verify that the new Assign will be deleted.

       

            • Original description by Eric ---*

      We have a site where a teacher setup a course restore with the 'delete course contents' setting enabled. It failed after the delete course content step, but before anything is meaningfully restored to the course. When it failed, the teacher went on to put their content in the course another way.

      But because adhoc tasks are always re-tried if they fail, guess what? Once a day, it fires off the restore event, wiping the course content, including any student work from that day...

      I would argue that something like restore should never retry - it tries, and if it fails, then it fails, and that's that. There is too much risk that you end up with a perpetually increasing amount of things in the course (if it partially completes) or something like this.

      While of course we could just wrap the entire restore task in a try-catch(Throwable), so it never fails, I think that isn't a good solution, because then to logging, it appears successful.

      I think we should add a method the adhoc_task abstract called something like allow_retry(): bool that is checked by the cron adhock runner if a adhock task threw an exception. That will allow tasks be reported as a failure, and to implement their own logic on if they should be resubmitted (including some that might just always return false, or some that might use fail delay, or something else to determine that they have failed a number of times, and to stop retrying).

      Attachments

        Issue Links

          Activity

            People

              huongn@moodle.com Huong Nguyen
              emerrill Eric Merrill
              Stevani Andolo Stevani Andolo
              Ilya Tregubov Ilya Tregubov
              Kim Jared Lucas Kim Jared Lucas
              Votes:
              3 Vote for this issue
              Watchers:
              22 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - 0 minutes
                  0m
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 1 week, 6 hours, 42 minutes
                  1w 6h 42m

                  Clockify

                    Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.