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

Allow graceful fast exit of cron via sigterm

    XMLWordPrintable

    Details

    • Testing Instructions:
      Hide

      1) Install this plugin just to make testing easier:

      https://github.com/catalyst/moodle-tool_testtasks

       

      2) Queue up 5 ad hoc tasks that each take 5 seconds to run:

      php admin/tool/testtasks/cli/queue_adhoc_tasks.php -n=5 -d=5

       

      3) Run the standalone ad hoc task processor:

      php admin/tool/task/cli/adhoc_task.php --execute
      

       

      4) Watch it for a little while, then press Control C, instead of immediately exiting it should gracefully finish what it was doing, and then exit instead of picking up it's next task:

      == Exiting gracefully, please wait ... ==
      

       

      5) Repeat the above, but press Control C twice, the second time it will do a hard exit.

      == Exiting right NOW == 
      

       

      6)  Rinse and repeat with admin/cli/cron.php but you need to carefully kill it during both the scheduled tasks and the ad hoc tasks.

       7) The tests above capture SIGINT, for completeness also re-test but instead of killing via Ctrl+C, open another terminal and kill is using:

      kill [pid]

      This should also result in the 'Exiting gracefully' message.

       

       

      Show
      1) Install this plugin just to make testing easier: https://github.com/catalyst/moodle-tool_testtasks   2) Queue up 5 ad hoc tasks that each take 5 seconds to run: php admin/tool/testtasks/cli/queue_adhoc_tasks.php -n= 5 -d= 5   3) Run the standalone ad hoc task processor: php admin/tool/task/cli/adhoc_task.php --execute   4) Watch it for a little while, then press Control C, instead of immediately exiting it should gracefully finish what it was doing, and then exit instead of picking up it's next task: == Exiting gracefully, please wait ... ==   5) Repeat the above, but press Control C twice, the second time it will do a hard exit. == Exiting right NOW ==    6)  Rinse and repeat with admin/cli/cron.php but you need to carefully kill it during both the scheduled tasks and the ad hoc tasks.  7) The tests above capture SIGINT, for completeness also re-test but instead of killing via Ctrl+C, open another terminal and kill is using: kill [pid] This should also result in the 'Exiting gracefully' message.    
    • Affected Branches:
      MOODLE_34_STABLE
    • Pull Master Branch:
      MDL-59594-SIGINT

      Description

      Allow a cron to shutdown cleanly by handling SIGTERM / SIGNIT and waiting for the current task to finish and then exit.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                brendanheywood Brendan Heywood
                Reporter:
                brendanheywood Brendan Heywood
                Peer reviewer:
                Andrew Nicols
                Participants:
                Component watchers:
                Andrew Nicols, Mathew May, Michael Hawkins, Shamim Rezaie, Simey Lameze, Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Sara Arjona (@sarjona), Víctor Déniz Falcón
              • Votes:
                2 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 1 hour, 30 minutes
                  1h 30m