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

Allow graceful fast exit of cron.php / adhoc_task.php via SIGTERM or SIGINT

    XMLWordPrintable

Details

    • MOODLE_34_STABLE, MOODLE_39_STABLE
    • MOODLE_39_STABLE
    • MDL-59594-SIGINT
    • Hide

      1) Install this plugin just to make testing easier:

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

      git clone https://github.com/catalyst/moodle-tool_testtasks.git admin/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 git clone https://github.com/catalyst/moodle-tool_testtasks.git admin/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.    

    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

              brendanheywood Brendan Heywood
              brendanheywood Brendan Heywood
              Andrew Lyons Andrew Lyons
              Adrian Greeve Adrian Greeve
              Mihail Geshoski Mihail Geshoski
              Andrew Lyons, Huong Nguyen, Jun Pataleta, Michael Hawkins, Shamim Rezaie, Simey Lameze, Stevani Andolo, Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Ilya Tregubov, Laurent David, Raquel Ortega, Sara Arjona (@sarjona)
              Votes:
              2 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                15/Jun/20

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Time Spent - 3 hours, 36 minutes Remaining Estimate - 3 days, 6 hours, 30 minutes
                  3d 6h 30m
                  Logged:
                  Time Spent - 3 hours, 36 minutes Remaining Estimate - 3 days, 6 hours, 30 minutes
                  3h 36m