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

convert_submission adhoc task throws exceptions when conversion needs polling

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Blocker Blocker
    • 4.1
    • 4.1
    • Assignment
    • MOODLE_401_STABLE
    • MOODLE_401_STABLE
    • MDL-75247-master
    • Hide

      Setup

      1. Install and enable the dummy fileconverter:
        1. git clone git@github.com:catalyst/moodle-fileconverter_dummy.git files/converter/dummy
        2. Browse to "Site administration" > "Plugins" > "Document converters" > "Manage document converters" and enable the dummy converter by "opening the eye" - ensure other converters are disabled
      2. Create a course and add an assignment with only the "Online text" submission type enabled

      Normal flow

      1. Enrol a student in the course
      2. As the student, make a submission for the assignment (make a note of what you type for the online text submission)
      3. From the CLI run: php admin/cli/adhoc_task.php -e
      4. Verify you see the following in the output:

        Dummy conversion started.
        Conversion still in progress. Requeueing self to check again.
        

      5. Check the mdl_task_adhoc table and verify there is a row containing "\assignfeedback_editpdf\task\convert_submission" in the classname column
      6. Wait 60 seconds
      7. Run php admin/cli/adhoc_task.php -e again
      8. Verify you see the following in the output:

        Dummy conversion completed.
        

      9. As the admin, browse the the assignment and press "View all submissions"
      10. Press "Grade" for the student who submitted
      11. Verify the same text entered for the submission is visible in the grader (there will be some additional HTML around it, that's fine)

      Error flow

      1. Hack the function get_combined_pdf_for_attempt in mod/assign/feedback/editpdf/classes/document_services.php so that it throws an exception immediately, like so:

        mod/assign/feedback/editpdf/classes/document_services.php

        335
        public static function get_combined_pdf_for_attempt($assignment, $userid, $attemptnumber) {
        336
            throw new \moodle_exception('exceptiontest');
        337
            $document = self::get_combined_document_for_attempt($assignment, $userid, $attemptnumber);
        

      2. Enrol a student in the course
      3. As the student, make a submission for the assignment (make a note of what you type for
      4. Check the mdl_task_adhoc table and take note of the ID of the "\assignfeedback_editpdf\task\convert_submission" task
      5. From the CLI run: php admin/cli/adhoc_task.php -e
      6. Verify an exception is thrown with the message: "Adhoc task failed: assignfeedback_editpdf\task\convert_submission,error/exceptiontest"
      7. Check the mdl_task_adhoc table and verify the row from earlier is still there, and now has a value of 60 in the "faildelay" column
      8. Revert the change to document_services.php (remove the exception throw)
      9. Wait 60 seconds
      10. Run: php admin/cli/adhoc_task.php -e
      11. Verify you see the following in the output:

        Dummy conversion started.
        Conversion still in progress. Requeueing self to check again.
        

      12. Check the mdl_task_adhoc table and verify a new task was added, take note of its ID
      13. Hack document_services.php again, adding the exception as before
      14. Run: php admin/cli/adhoc_task.php -e
      15. Verify the exception is thrown again, and the faildelay was added to the row in the mdl_task_adhoc table
      16. Revert the change to document_services.php and wait 60 seconds
      17. Run: php admin/cli/adhoc_task.php -e
      18. Verify you see the following in the output:

        Dummy conversion completed.
        

      19. As the admin, browse the the assignment and press "View all submissions"
      20. Press "Grade" for the student who submitted
      21. Verify the same text entered for the submission is visible in the grader (there will be some additional HTML around it, that's fine)
      Show
      Setup Install and enable the dummy fileconverter: git clone git@github.com:catalyst/moodle-fileconverter_dummy.git files/converter/dummy Browse to "Site administration" > "Plugins" > "Document converters" > "Manage document converters" and enable the dummy converter by "opening the eye" - ensure other converters are disabled Create a course and add an assignment with only the "Online text" submission type enabled Normal flow Enrol a student in the course As the student, make a submission for the assignment (make a note of what you type for the online text submission) From the CLI run: php admin/cli/adhoc_task.php -e Verify you see the following in the output: Dummy conversion started. Conversion still in progress. Requeueing self to check again. Check the mdl_task_adhoc table and verify there is a row containing "\assignfeedback_editpdf\task\convert_submission" in the classname column Wait 60 seconds Run php admin/cli/adhoc_task.php -e again Verify you see the following in the output: Dummy conversion completed. As the admin, browse the the assignment and press "View all submissions" Press "Grade" for the student who submitted Verify the same text entered for the submission is visible in the grader (there will be some additional HTML around it, that's fine) Error flow Hack the function get_combined_pdf_for_attempt in mod/assign/feedback/editpdf/classes/document_services.php so that it throws an exception immediately, like so: mod/assign/feedback/editpdf/classes/document_services.php 335 public static function get_combined_pdf_for_attempt( $assignment , $userid , $attemptnumber ) { 336 throw new \moodle_exception( 'exceptiontest' ); 337 $document = self::get_combined_document_for_attempt( $assignment , $userid , $attemptnumber ); Enrol a student in the course As the student, make a submission for the assignment (make a note of what you type for Check the mdl_task_adhoc table and take note of the ID of the "\assignfeedback_editpdf\task\convert_submission" task From the CLI run: php admin/cli/adhoc_task.php -e Verify an exception is thrown with the message: "Adhoc task failed: assignfeedback_editpdf\task\convert_submission,error/exceptiontest" Check the mdl_task_adhoc table and verify the row from earlier is still there, and now has a value of 60 in the "faildelay" column Revert the change to document_services.php (remove the exception throw) Wait 60 seconds Run: php admin/cli/adhoc_task.php -e Verify you see the following in the output: Dummy conversion started. Conversion still in progress. Requeueing self to check again. Check the mdl_task_adhoc table and verify a new task was added, take note of its ID Hack document_services.php again, adding the exception as before Run: php admin/cli/adhoc_task.php -e Verify the exception is thrown again, and the faildelay was added to the row in the mdl_task_adhoc table Revert the change to document_services.php and wait 60 seconds Run: php admin/cli/adhoc_task.php -e Verify you see the following in the output: Dummy conversion completed. As the admin, browse the the assignment and press "View all submissions" Press "Grade" for the student who submitted Verify the same text entered for the submission is visible in the grader (there will be some additional HTML around it, that's fine)

      Prerequisites

      1. Revert MDL-73727

      Unfortunately MDL-73727 introduces a regression that prevents testing this issue properly, so it must be reverted first. See MDL-74910 for more detail.

      Replication steps

      1. Install and enable the attached fileconverter plugin
      2. Create a course with an assignment (default settings are fine) and a student
      3. As the student, submit something for the assignment
      4. Run: php admin/cli/adhoc_task.php -e you will see something like (NB: note the messages from the dummy converter that tell you what is happening)

        Execute adhoc task: assignfeedback_editpdf\task\convert_submission
        Adhoc task id: 8
        Adhoc task custom data: {"submissionid":"3","submissionattempt":"0"}
        ... started 16:35:18. Current memory use 14.2 MB.
        Converting submission for user id 12
        Hello from start_document_conversion
        ... used 33 dbqueries
        ... used 0.10417008399963 seconds
        Adhoc task failed: assignfeedback_editpdf\task\convert_submission,Coding error detected, it must be fixed by a programmer: Document conversion completed with status 0
        Backtrace:
        * line 359 of /lib/cronlib.php: call to assignfeedback_editpdf\task\convert_submission->execute()
        * line 198 of /lib/cronlib.php: call to cron_run_inner_adhoc_task()
        * line 131 of /admin/cli/adhoc_task.php: call to cron_run_adhoc_tasks()
        

      5. Wait 60 seconds (due to fail delay) and run it again: php admin/cli/adhoc_task.php -e and you will see:

        Execute adhoc task: assignfeedback_editpdf\task\convert_submission
        Adhoc task id: 8
        Adhoc task custom data: {"submissionid":"3","submissionattempt":"0"}
        ... started 16:38:35. Current memory use 14.2 MB.
        Converting submission for user id 12
        Hello from poll_onversion_status. The conversion is complete!
        The document has been successfully converted
        ... used 108 dbqueries
        ... used 1.3207869529724 seconds
        Adhoc task complete: assignfeedback_editpdf\task\convert_submission
        Ran 1 adhoc tasks found at Tue, 19 Jul 2022 16:38:35 +0800
        

      In the first call to adhoc_task.php the conversion was started as an asynchronous conversion; an exception is thrown, and the task is marked as failed by Moodle. This is not a failure case and should not cause the task to fail. On the second call, the dummy converter reports itself as completed so everything finishes. In the real world, an async conversion may require multiple polls, and the faildelay will needlessly delay completion of the conversion. Additionally, the exceptions will pollute logs.

      Instead, of throwing an exception when we get a non-complete status, we should check if the conversion is in progress, and if it is, requeue the adhoc task to poll again.

      This has the added benefit of allowing us to pass along how many conversion attempts have been made in the newly queued adhoc task. Allowing us to reimpliment $CFG->conversionattemptlimit which was removed without replacement in MDL-71468

        1. 14_MDL-75247.png
          14_MDL-75247.png
          15 kB
        2. 15_MDL-75247.png
          15_MDL-75247.png
          21 kB
        3. 18_MDL-75247.png
          18_MDL-75247.png
          15 kB
        4. 20_MDL-75247.png
          20_MDL-75247.png
          31 kB
        5. 26_MDL-75247.png
          26_MDL-75247.png
          31 kB
        6. 27_MDL-75247.png
          27_MDL-75247.png
          24 kB
        7. 31_MDL-75247.png
          31_MDL-75247.png
          15 kB
        8. 32_MDL-75247.png
          32_MDL-75247.png
          24 kB
        9. 35_MDL-75247.png
          35_MDL-75247.png
          52 kB
        10. 38_MDL-75247.png
          38_MDL-75247.png
          15 kB
        11. 41_MDL-75247.png
          41_MDL-75247.png
          28 kB

            cameron1729 cameron1729
            cameron1729 cameron1729
            Misha Golenkov Misha Golenkov
            Jake Dallimore Jake Dallimore
            John Edward Pedregosa John Edward Pedregosa
            Votes:
            1 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 4 hours, 23 minutes
                4h 23m

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