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.