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

Enable cli/adhoc_task.php to be run as a pseudo daemon with --keep-alive=60

    XMLWordPrintable

Details

    • MOODLE_38_STABLE
    • MOODLE_39_STABLE
    • MDL-66925-adhoc-keep-alive
    • Hide

      Setup

      1) Install this plugin just to make testing easier:

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

       

      Testing scenario 1. Execution without keep-alive

      1) Queue up just a couple ad hoc tasks 

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

      2) Run the ad hoc task runner:

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

      3) Check the ad hoc task runner runs and then halts normally afterwards:

      Execute adhoc task: tool_testtasks\task\timed_adhoc_task
      ... started 14:08:01. Current memory use 15.2MB.
      Starting adhoc task '1 of 1' wth duration: 1
      adhoc task running: 1/1 seconds
      Ending adhoc task '1 of 1' with duration: 1
      ... used 0 dbqueries
      ... used 1.0032410621643 seconds
      Adhoc task complete: tool_testtasks\task\timed_adhoc_task
      Ran 1 adhoc tasks found at Tue, 03 Dec 2019 14:08:01 +0100

       

      Testing scenario 2. Execution with short keep alive

      1) Run the ad hoc task runner in keep alive mode:

      php admin/tool/task/cli/adhoc_task.php --execute --keep-alive=10 
      

      2) Check it sits there waiting and drawing dots every second ...

      Waiting for more adhoc tasks to be queued ..... 
      

      3) Check after 10 seconds it exits.

       

      Testing scenario 3. Execution with long keep alive

      1) Run the ad hoc task runner and keep it alive for ages

      php admin/tool/task/cli/adhoc_task.php -e -k=1000
      

       2) In another terminal queue up a task:

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

      3) In the first tab, check this task get processed within a second.

      Waiting for more adhoc tasks to be queued ..........
      Execute adhoc task: tool_testtasks\task\timed_adhoc_task
      ... started 14:13:42. Current memory use 15.2MB.
      Starting adhoc task '1 of 1 ' wth duration: 1
      adhoc task running: 1/1 seconds
      Ending adhoc task '1 of 1 ' with duration: 1
      ... used 0 dbqueries
      ... used 1.0078918933868 seconds
      Adhoc task complete: tool_testtasks\task\timed_adhoc_task

      4) In the first tab, check it will go back to waiting.

      Waiting for more adhoc tasks to be queued .............
      

      5) In the second tab, purge the cache.

      php admin/cli/purge_caches.php
      

      6) In the first tab, check the adhoc task script exits as normal.

       
       

      Show
      Setup 1) Install this plugin just to make testing easier: https://github.com/catalyst/moodle-tool_testtasks   Testing scenario 1. Execution without keep-alive 1) Queue up just a couple ad hoc tasks  php admin/tool/testtasks/cli/queue_adhoc_tasks.php -d= 1 -n= 1 2) Run the ad hoc task runner: php admin/tool/task/cli/adhoc_task.php -e 3) Check the ad hoc task runner runs and then halts normally afterwards: Execute adhoc task: tool_testtasks\task\timed_adhoc_task ... started 14 : 08 : 01 . Current memory use 15 .2MB. Starting adhoc task '1 of 1' wth duration: 1 adhoc task running: 1 / 1 seconds Ending adhoc task '1 of 1' with duration: 1 ... used 0 dbqueries ... used 1.0032410621643 seconds Adhoc task complete: tool_testtasks\task\timed_adhoc_task Ran 1 adhoc tasks found at Tue, 03 Dec 2019 14 : 08 : 01 + 0100   Testing scenario 2. Execution with short keep alive 1) Run the ad hoc task runner in keep alive mode: php admin/tool/task/cli/adhoc_task.php --execute --keep-alive= 10   2) Check it sits there waiting and drawing dots every second ... Waiting for more adhoc tasks to be queued .....  3) Check after 10 seconds it exits.   Testing scenario 3. Execution with long keep alive 1) Run the ad hoc task runner and keep it alive for ages php admin/tool/task/cli/adhoc_task.php -e -k= 1000  2) In another terminal queue up a task: php admin/tool/testtasks/cli/queue_adhoc_tasks.php -d= 1 -n= 1   3) In the first tab, check this task get processed within a second. Waiting for more adhoc tasks to be queued .......... Execute adhoc task: tool_testtasks\task\timed_adhoc_task ... started 14 : 13 : 42 . Current memory use 15 .2MB. Starting adhoc task '1 of 1 ' wth duration: 1 adhoc task running: 1 / 1 seconds Ending adhoc task '1 of 1 ' with duration: 1 ... used 0 dbqueries ... used 1.0078918933868 seconds Adhoc task complete: tool_testtasks\task\timed_adhoc_task 4) In the first tab, check it will go back to waiting. Waiting for more adhoc tasks to be queued ............. 5) In the second tab, purge the cache. php admin/cli/purge_caches.php 6) In the first tab, check the adhoc task script exits as normal.    

    Description

      Usually this gets kicks off every minute from cron.d but this means that depending on when a task get queued it could be up to a minute before it even gets picked up.

      We currently work around this by firing off a process at smaller intervals such as every 30 or 15 seconds.

      It would be better if we just just say 'run the ad hoc task queue for 1 minute'. If it gets to the end of the queue then just sit there and poll it to see if anything new gets added.

      Attachments

        Issue Links

          Activity

            People

              brendanheywood Brendan Heywood
              brendanheywood Brendan Heywood
              Matt Porritt Matt Porritt
              Sara Arjona (@sarjona) Sara Arjona (@sarjona)
              Gladys Basiana Gladys Basiana
              Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Ilya Tregubov, Laurent David, Raquel Ortega, Sara Arjona (@sarjona)
              Votes:
              1 Vote for this issue
              Watchers:
              10 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                15/Jun/20

                Time Tracking

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