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:
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.