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

Add new options to admin/cli/adhoc_task.php and from admin web UI

XMLWordPrintable

    • MOODLE_311_STABLE, MOODLE_400_STABLE, MOODLE_401_STABLE, MOODLE_402_STABLE
    • MOODLE_402_STABLE
    •  MDL-70975-adhoc-carneval
    • Hide

      Preparation

      Cron

      To test this new features please make sure that the cron script admin/cli/cron.php is not scheduled to run automatically in crontab or any other config file observed by cron.

      Install tool_testtask:

      git clone git@github.com:catalyst/moodle-tool_testtasks.git admin/tool/testtasks
      

      You can queue a number of different task classes: timed_adhoc_task (default), another_timed_adhoc_task and two_second_task

      Configure php binary path

      Go to Administration > Server > System paths and fill in pathtophp. If you don't know the path, on the command line, run:

      which php
      

      Web UI

      Schedule some ad hoc tasks

      1. Command line, run:

      php admin/tool/testtasks/cli/queue_adhoc_tasks.php
      php admin/tool/testtasks/cli/queue_adhoc_tasks.php --class=tool_testtasks\\task\\another_timed_adhoc_task -d=10
      php admin/tool/testtasks/cli/queue_adhoc_tasks.php --class=tool_testtasks\\task\\another_timed_adhoc_task --successrate=0
      php admin/tool/testtasks/cli/queue_adhoc_tasks.php --class=tool_testtasks\\task\\two_second_task --numberoftasks=2
      php admin/tool/testtasks/cli/queue_adhoc_tasks.php --class=tool_testtasks\\task\\recursive_task
      

      2. Observe double backslashes, for the shell escape reasons.
      Expected output is similar to:

      Queue task with this data: {"label":"1 of 1","duration":1,"success":100}
        

      for the tasks that will succeed another_timed_adhoc_task should have "success":0.

      3. Navigate to Site Administration > Server > Tasks > Ad hoc tasks.
      Verify the list of the tasks shown is as expected:

      • one timed_adhoc_task
      • two of the another_timed_adhoc_task (one is set to fail on run)
      • two of the two_second_task
      • one recursive_task

      Tasks summary page

      Class name column holds the task class name, which is a hyperlink to the same page with tasks that belong only to selected class. Below that should be a Run all for class name link.

      In case of failed tasks for a class, Ad hoc tasks failed column should be red, and have Run all failed link.

      Run all for class name

      1. Click on Run all below another_timed_adhoc_task link. It should open Run all tasks confirmation page.

      2. Confirm that only tasks that belong to the selected class are displayed.

      3. Click on the Run now button. Run all tasks page should open in run/output mode. You should get output similar to

      Server Time: Thu, 07 Jul 2022 05:28:07 +0100
      Execute adhoc task: tool_testtasks\task\another_timed_adhoc_task
      ... started 05:28:07. Current memory use 13.8 MB.
      Starting ANOTHER adhoc task '1 of 1' with duration: 1
      adhoc ANOTHER task running: 1/10 seconds
      adhoc ANOTHER task running: 2/10 seconds
      adhoc ANOTHER task running: 3/10 seconds
      adhoc ANOTHER task running: 4/10 seconds
      ...
      Ending ANOTHER adhoc task '1 of 1'
      ... used 0 dbqueries
      ... used 2.0080771446228 seconds
      Adhoc task complete: tool_testtasks\task\another_timed_adhoc_task
      Execute adhoc task: tool_testtasks\task\another_timed_adhoc_task
      ... started 05:28:07. Current memory use 13.8 MB.
      Starting ANOTHER adhoc task '1 of 1' with duration: 1
      adhoc ANOTHER task running: 1/1 seconds
      Ending ANOTHER adhoc task '1 of 1' with duration: 1 with exception
      ... used 0 dbqueries
      ... used 1.0043499469757 seconds
      Adhoc task failed: tool_testtasks\task\another_timed_adhoc_task,Exploding!
      Ran 2 adhoc tasks found at Thu, 07 Jul 2022 05:28:07 +0100
      

      4. Confirm that adhoc ANOTHER task running: n/10 seconds lines were appearing in real time, one second apart.

      5. Click on the Back to ad hoc tasks link at the bottom.

      6. Confirm that there's one failed entry for another_timed_adhoc_task with the Run all failed link.

      Run all failed tasks for class name

      1. Click on Run all failed for another_timed_adhoc_task. It will open the same confirmation page as above, except with only one (failed) task.

      2. After confirming, you should get output at the top similar to the previous failed bit.

      Tasks for a class page

      1. On the summary page, click on the two_second_task link. You should see a page with all tasks for the selected class.

      Fail delay heading should have Show failed only link. If you click on that it should display only failed tasks for the class, and the link should toggle to Show all.

      In the Next run column there should be Run now link.

      2. Confirm that at the bottom, there are two links:

      • Run all, the effect is the same as on the Summary page
      • Show ad hoc tasks summary, which returns to the Summary page

      Run individual task

      1. Click on Run now for any task. It should open the confirmation page with only one (selected) task.

      2. After confirming/running click on the Back to ad hoc tasks link. After individual task run it will return to the Cass tasks page

      3. Confirm that the task that we just ran has disappeared from the list.

      CLI

      You should still have one of the timed_adhoc_task and another_timed_adhoc_task from the previous tests. Schedule some more tasks: as in Web UI - Scheduled some ad hoc tasks:

      php admin/tool/testtasks/cli/queue_adhoc_tasks.php
      php admin/tool/testtasks/cli/queue_adhoc_tasks.php --class=tool_testtasks\\task\\two_second_task --numberoftasks=2
      

      Navigate to Site Administration > Server > Tasks > Ad hoc tasks.

      --classname option

      1. Run

      php admin/cli/adhoc_task.php --classname=tool_testtasks\\task\\two_second_task
      

      2. Verify that the task run output is as in Tasks summary page - Run all tasks of certain class.

      3. Refresh the Tasks summary page and verify that timed_adhoc_task is in the list, and there is no two_second_task.

      --id option

      1. Click on the timed_adhoc_task link. You should see a page with all tasks for the selected class.

      2. Observe task id of the timed_adhoc_task in the Class name column.

      3. Run

      php admin/cli/adhoc_task.php --id=[selected id]
      

      4. Verify that the task run output is as in Run individual task.

      5. Refresh the Tasks for class page and verify that the task that has just been run is removed.

      --failed option

      1. Click on the Back to ad hoc tasks link to return to the Tasks summary page, then on the another_timed_adhoc_task link. You should see a page with all tasks for the selected class.

      2. Verify that another_timed_adhoc_task is in the failed state - Fail delay column is red, and observe the Next run time, how far it is in the future (can be ASAP as well).

      3. Run

      php admin/cli/adhoc_task.php --failed
      

      4. Verify that the task run output is as in Run individual task, reporting failure.

      5. Refresh the Tasks for class page and verify that another_timed_adhoc_task has its Next run in the future, delayed more than in the step 2. - depending on how fast you performed the steps, roughly doubled.

      --taskslimit option

      Schedule some more tasks: as in Web UI - Scheduled some ad hoc tasks.
      1. Run

      php admin/cli/adhoc_task.php --taskslimit=1
      

      2. Verify that the task run output is as in Run individual task, and is for one task only.

      Show
      Preparation Cron To test this new features please make sure that the cron script admin/cli/cron.php is not scheduled to run automatically in crontab or any other config file observed by cron . Install tool_testtask : git clone git@github.com:catalyst/moodle-tool_testtasks.git admin/tool/testtasks You can queue a number of different task classes: timed_adhoc_task (default), another_timed_adhoc_task and two_second_task Configure php binary path Go to Administration > Server > System paths and fill in pathtophp . If you don't know the path, on the command line, run: which php Web UI Schedule some ad hoc tasks 1. Command line, run: php admin/tool/testtasks/cli/queue_adhoc_tasks.php php admin/tool/testtasks/cli/queue_adhoc_tasks.php --class=tool_testtasks\\task\\another_timed_adhoc_task -d=10 php admin/tool/testtasks/cli/queue_adhoc_tasks.php --class=tool_testtasks\\task\\another_timed_adhoc_task --successrate=0 php admin/tool/testtasks/cli/queue_adhoc_tasks.php --class=tool_testtasks\\task\\two_second_task --numberoftasks=2 php admin/tool/testtasks/cli/queue_adhoc_tasks.php --class=tool_testtasks\\task\\recursive_task 2. Observe double backslashes, for the shell escape reasons. Expected output is similar to: Queue task with this data: {"label":"1 of 1","duration":1,"success":100} for the tasks that will succeed another_timed_adhoc_task should have "success":0 . 3. Navigate to Site Administration > Server > Tasks > Ad hoc tasks. Verify the list of the tasks shown is as expected: one timed_adhoc_task two of the another_timed_adhoc_task (one is set to fail on run) two of the two_second_task one recursive_task Tasks summary page Class name column holds the task class name, which is a hyperlink to the same page with tasks that belong only to selected class. Below that should be a Run all for class name link. In case of failed tasks for a class, Ad hoc tasks failed column should be red, and have Run all failed link. Run all for class name 1. Click on Run all below another_timed_adhoc_task link. It should open Run all tasks confirmation page. 2. Confirm that only tasks that belong to the selected class are displayed. 3. Click on the Run now button. Run all tasks page should open in run/output mode. You should get output similar to Server Time: Thu, 07 Jul 2022 05:28:07 +0100 Execute adhoc task: tool_testtasks\task\another_timed_adhoc_task ... started 05:28:07. Current memory use 13.8 MB. Starting ANOTHER adhoc task '1 of 1' with duration: 1 adhoc ANOTHER task running: 1/10 seconds adhoc ANOTHER task running: 2/10 seconds adhoc ANOTHER task running: 3/10 seconds adhoc ANOTHER task running: 4/10 seconds ... Ending ANOTHER adhoc task '1 of 1' ... used 0 dbqueries ... used 2.0080771446228 seconds Adhoc task complete: tool_testtasks\task\another_timed_adhoc_task Execute adhoc task: tool_testtasks\task\another_timed_adhoc_task ... started 05:28:07. Current memory use 13.8 MB. Starting ANOTHER adhoc task '1 of 1' with duration: 1 adhoc ANOTHER task running: 1/1 seconds Ending ANOTHER adhoc task '1 of 1' with duration: 1 with exception ... used 0 dbqueries ... used 1.0043499469757 seconds Adhoc task failed: tool_testtasks\task\another_timed_adhoc_task,Exploding! Ran 2 adhoc tasks found at Thu, 07 Jul 2022 05:28:07 +0100 4. Confirm that adhoc ANOTHER task running: n/10 seconds lines were appearing in real time, one second apart. 5. Click on the Back to ad hoc tasks link at the bottom. 6. Confirm that there's one failed entry for another_timed_adhoc_task with the Run all failed link. Run all failed tasks for class name 1. Click on Run all failed for another_timed_adhoc_task . It will open the same confirmation page as above, except with only one (failed) task. 2. After confirming, you should get output at the top similar to the previous failed bit. Tasks for a class page 1. On the summary page, click on the two_second_task link. You should see a page with all tasks for the selected class. Fail delay heading should have Show failed only link. If you click on that it should display only failed tasks for the class, and the link should toggle to Show all . In the Next run column there should be Run now link. 2. Confirm that at the bottom, there are two links: Run all , the effect is the same as on the Summary page Show ad hoc tasks summary , which returns to the Summary page Run individual task 1. Click on Run now for any task. It should open the confirmation page with only one (selected) task. 2. After confirming/running click on the Back to ad hoc tasks link. After individual task run it will return to the Cass tasks page 3. Confirm that the task that we just ran has disappeared from the list. CLI You should still have one of the timed_adhoc_task and another_timed_adhoc_task from the previous tests. Schedule some more tasks: as in Web UI - Scheduled some ad hoc tasks : php admin/tool/testtasks/cli/queue_adhoc_tasks.php php admin/tool/testtasks/cli/queue_adhoc_tasks.php --class=tool_testtasks\\task\\two_second_task --numberoftasks=2 Navigate to Site Administration > Server > Tasks > Ad hoc tasks. --classname option 1. Run php admin/cli/adhoc_task.php --classname=tool_testtasks\\task\\two_second_task 2. Verify that the task run output is as in Tasks summary page - Run all tasks of certain class. 3. Refresh the Tasks summary page and verify that timed_adhoc_task is in the list, and there is no two_second_task . --id option 1. Click on the timed_adhoc_task link. You should see a page with all tasks for the selected class. 2. Observe task id of the timed_adhoc_task in the Class name column. 3. Run php admin/cli/adhoc_task.php --id=[selected id] 4. Verify that the task run output is as in Run individual task . 5. Refresh the Tasks for class page and verify that the task that has just been run is removed. --failed option 1. Click on the Back to ad hoc tasks link to return to the Tasks summary page , then on the another_timed_adhoc_task link. You should see a page with all tasks for the selected class. 2. Verify that another_timed_adhoc_task is in the failed state - Fail delay column is red, and observe the Next run time, how far it is in the future (can be ASAP as well). 3. Run php admin/cli/adhoc_task.php --failed 4. Verify that the task run output is as in Run individual task , reporting failure. 5. Refresh the Tasks for class page and verify that another_timed_adhoc_task has its Next run in the future, delayed more than in the step 2. - depending on how fast you performed the steps, roughly doubled. --taskslimit option Schedule some more tasks: as in Web UI - Scheduled some ad hoc tasks . 1. Run php admin/cli/adhoc_task.php --taskslimit=1 2. Verify that the task run output is as in Run individual task , and is for one task only.

      Would be good to have an option for adhoc_task.php to run one adhoc class only.

      New options that would be good to have:

      • id - a task id to be run. Using this option we will be able to re-run failed adhoc tasks via UI (MDL-68407).
      • classname - run a specific classname only. Can be used with --ignorelimits.
      • number - number of tasks to be run. Slightly similar to --keep-alive, but capped by number of tasks. 

      To profile a long running task `--number=1 --classname='\some\class\name' --ignorelimits` options can be used.

        1. (I) Passed -- (Master)MDL-70975.png
          68 kB
          Kim Jared Lucas
        2. (II) Passed -- (Master)MDL-70975.png
          61 kB
          Kim Jared Lucas
        3. (III) Passed -- (Master)MDL-70975.png
          71 kB
          Kim Jared Lucas
        4. (IV) Passed -- (Master)MDL-70975.png
          77 kB
          Kim Jared Lucas
        5. (IX) Passed -- (Master)MDL-70975.png
          37 kB
          Kim Jared Lucas
        6. (V) Passed -- (Master)MDL-70975.png
          66 kB
          Kim Jared Lucas
        7. (VI) Passed -- (Master)MDL-70975.png
          180 kB
          Kim Jared Lucas
        8. (VII) Passed -- (Master)MDL-70975.png
          169 kB
          Kim Jared Lucas
        9. (VIII) Passed -- (Master)MDL-70975.png
          174 kB
          Kim Jared Lucas
        10. image-2022-07-13-10-34-25-564.png
          98 kB
          Kevin Pham
        11. image-2022-09-15-14-42-56-918.png
          80 kB
          Kevin Pham
        12. image-2023-04-11-15-34-04-641.png
          20 kB
          Ilya Tregubov
        13. Once output has finished - scrolling breaks 2022-09-15 14-45.gif
          1.39 MB
          Kevin Pham
        14. Screenshot from 2023-04-04 12-51-06.png
          52 kB
          Ilya Tregubov
        15. Screenshot from 2023-04-04 12-51-50.png
          31 kB
          Ilya Tregubov
        16. Screenshot from 2023-04-04 12-54-10.png
          26 kB
          Ilya Tregubov

            srdjan Srdjan Jankovic
            mikhailgolenkov Misha Golenkov
            Kevin Pham Kevin Pham
            Ilya Tregubov Ilya Tregubov
            Kim Jared Lucas Kim Jared Lucas
            Votes:
            9 Vote for this issue
            Watchers:
            36 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 day, 5 hours, 53 minutes
                1d 5h 53m

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