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

moodle_exception can't be caught in course_backup_task class

    XMLWordPrintable

    Details

    • Testing Instructions:
      Hide

      1. Create "MDL-67502" course.

      2. Set Automated backup to manual:

      php admin/cli/cfg.php --component=backup --name=backup_auto_active --set=2

      3. Set the schedule:

      php admin/cli/cfg.php --component=backup --name=backup_auto_weekdays --set='1111111'

      4. Set execute time:

      php admin/cli/cfg.php --component=backup --name=backup_auto_hour --set=1

      5. Generate mdl_backup_courses records:

      php admin/cli/automated_backups.php

      6. Update nextstarttime:
      Postgres:

      update mdl_backup_courses set nextstarttime = round(extract(epoch from now()));

      MySQL:

      update mdl_backup_courses set nextstarttime = UNIX_TIMESTAMP();

      7. Generate ad-hoc task:

      php admin/cli/automated_backups.php

      8. Confirm, that ad-hoc task was created:

      select classname, nextruntime, faildelay, customdata from mdl_task_adhoc where classname = '\core\task\course_backup_task';

      9. Delete record from mdl_backup_courses table:

      delete from mdl_backup_courses;

      10. Run cron:

      php admin/cli/cron.php

      8. Confirm, that cron log has correct exception and looks like:

      Processing automated backup for course: MDL-67502
      Automated backup for course: MDL-67502 encounters an error.
      Exception: Can't find data record in database table backup_courses.
      Debug: SELECT * FROM {backup_courses} WHERE courseid = ? AND laststatus = ?
      [array (
       0 => '1',
       1 => 6,
      )]
      Automated backup for course: MDL-67502 completed.
      ... used 5 dbqueries
      ... used 0.0023899078369141 seconds
      Adhoc task complete: core\task\course_backup_task
      Cron script completed correctly

       

      9. Run SQL:

      select classname, nextruntime, faildelay, customdata from mdl_task_adhoc where classname = '\core\task\course_backup_task';

      10. Confirm, that ad-hoc task has been finished:

       

      classname | nextruntime | faildelay | customdata 
      -----------+-------------+-----------+------------
      (0 rows)
       
      

       

      Show
      1. Create " MDL-67502 " course. 2. Set Automated backup to manual: php admin/cli/cfg.php --component=backup --name=backup_auto_active --set= 2 3. Set the schedule: php admin/cli/cfg.php --component=backup --name=backup_auto_weekdays --set= '1111111' 4. Set execute time: php admin/cli/cfg.php --component=backup --name=backup_auto_hour --set= 1 5. Generate mdl_backup_courses records: php admin/cli/automated_backups.php 6. Update nextstarttime: Postgres: update mdl_backup_courses set nextstarttime = round(extract(epoch from now())); MySQL: update mdl_backup_courses set nextstarttime = UNIX_TIMESTAMP(); 7. Generate ad-hoc task: php admin/cli/automated_backups.php 8. Confirm , that ad-hoc task was created: select classname, nextruntime, faildelay, customdata from mdl_task_adhoc where classname = '\core\task\course_backup_task' ; 9. Delete record from mdl_backup_courses table: delete from mdl_backup_courses; 10. Run cron: php admin/cli/cron.php 8. Confirm , that cron log has correct exception and looks like: Processing automated backup for course: MDL- 67502 Automated backup for course: MDL- 67502 encounters an error. Exception: Can't find data record in database table backup_courses. Debug: SELECT * FROM {backup_courses} WHERE courseid = ? AND laststatus = ? [array ( 0 => '1' , 1 => 6 , )] Automated backup for course: MDL- 67502 completed. ... used 5 dbqueries ... used 0.0023899078369141 seconds Adhoc task complete: core\task\course_backup_task Cron script completed correctly   9. Run SQL: select classname, nextruntime, faildelay, customdata from mdl_task_adhoc where classname = '\core\task\course_backup_task' ; 10. Confirm , that ad-hoc task has been finished:   classname | nextruntime | faildelay | customdata -----------+-------------+-----------+------------ ( 0 rows)    
    • Affected Branches:
      MOODLE_39_STABLE
    • Fixed Branches:
      MOODLE_39_STABLE
    • Pull from Repository:
    • Pull Master Branch:
      master_MDL-67502

      Description

      course_backup_task class is defined in the core\task namespace, while execute() method is trying to catch "moodle_exception" (not "\moodle_exception"):

      https://github.com/moodle/moodle/blob/8cf4c97217230e74e57e41f24e8afbbc8393eb79/lib/classes/task/course_backup_task.php#L87

       

      For example, when corresponding record is missing in "mdl_backup_courses" table task runner doesn't catch

      course_backup_task's  exception, throws it's own 

      core\task\course_backup_task,Can't find data record in database table backup_courses

      and leaves the ad-hoc task in the queue with incremented faildelay:

      moodle=# select classname, nextruntime, faildelay, customdata from mdl_task_adhoc where classname = '\core\task\course_backup_task';
       classname | nextruntime | faildelay | customdata 
      -------------------------------+-------------+-----------+--------------------------------
       \core\task\course_backup_task | 1576132773 | 240 | {"courseid":"1","adminid":"2"}
      (1 row)

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              mikhailgolenkov Mikhail Golenkov
              Reporter:
              mikhailgolenkov Mikhail Golenkov
              Peer reviewer:
              Sara Arjona (@sarjona)
              Integrator:
              Jake Dallimore
              Tester:
              Janelle Barcega
              Participants:
              Component watchers:
              Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Sara Arjona (@sarjona), Víctor Déniz Falcón
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Fix Release Date:
                15/Jun/20

                  Time Tracking

                  Estimated:
                  Original Estimate - 0 minutes
                  0m
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 55 minutes
                  55m