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

New api to allow adhoc tasks to communicate a progress bar / status back to the calling page

    • Hide
      Setup
      1. Install the testtasks admin tool on your moodle site:

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

      TESTING A SCHEDULED TASK
      1. Login to the terminal of your web server
      2. Run one of the example scheduled task scripts from the CLI:

      • `php admin/cli/scheduled_task.php --execute='\tool_testtasks\task\stored_progress_scheduled_task_manual`
      • `php admin/cli/scheduled_task.php --execute='\tool_testtasks\task\stored_progress_scheduled_task_iterations`
        This will start the task running, which will take some time.
        3. Confirm in the database you can see the record created in mdl_stored_progress and that it is updating as the task progresses.
        4. Whilst this is running, open your web browser and navigate to `yourmoodle.com/admin/tool/testtasks/storedprogress.php` this web page will show you all the running stored progress bars. 
        5. Confirm that you can see the progress bar and that it is updating every 5 seconds.
        6. Note: The `stored_progress_scheduled_task_manual` task will fail with an error. This is intentional so you can confirm that the progress bar stops with an error.
        7. Confirm that once the scheduled task has finished in the terminal, the progress bar in the web page completes and stops polling.
        8. Note: You can check if the bar is still polling by checking the Network tab of your web browser and looking for web service requests for the `core_poll_stored_progress` web service.

      TESTING A SCHEDULED TASK ON THE EXISTING RUNNING-TASKS PAGE
      1. Login to the terminal of your web server
      2. Run one of the example scheduled task scripts from the CLI:

      • `php admin/cli/scheduled_task.php --execute='local_example\task\stored_progress_scheduled_task_manual`
      • `php admin/cli/scheduled_task.php --execute='local_example\task\stored_progress_scheduled_task_iterations`
        This will start the task running, which will take some time.
        3. Confirm in the database you can see the record created in mdl_stored_progress and that it is updating as the task progresses.
        4. Whilst this is running, navigate to Site Admin -> Server -> Tasks Running Now
        5. Confirm that you can see the progress bar updating on this page whilst the task runs

       

      TESTING AN ADHOC TASK
      1. Login to the terminal of your web server
      2. Run the following script to scheduled an adhoc task: `php admin/tool/testtasks/cli/schedule_stored_progress_adhoc_task.php`. This will create an adhoc task and give you the command to run to execute it.
      3. Run the command you are given to execute the adhoc task.
      4. Confirm in the database that you can see the record created in mdl_stored_progress and that it is updating as the task progresses.
      5. Whilst this is running, open your web browser and navigate to `yourmoodle.com/admin/tool/testtasks/storedprogress.php` this web page will show you all the running stored progress bars. 
      6. Confirm that you can see the progress bar and that it is updating every 5 seconds.
      7. Confirm that once the scheduled task has finished in the terminal, the progress bar in the web page completes and stops polling.

       

      TESTING A CLI SCRIPT
      1. Login to the terminal of your web server
      2. Run the example script provided: `php admin/tool/testtasks/cli/stored_progress_watched_cli_script.php`
      3. Confirm that the progress bar is displayed in the terminal and updates as it progresses
      4. Confirm in the database that you can see the record created in mdl_stored_progress and that it is updating as the task progresses.
      5. Whilst this is running, open your web browser and navigate to `yourmoodle.com/admin/tool/testtasks/storedprogress.php` this web page will show you all the running stored progress bars. 
      6. Confirm that you can see the progress bar and that it is updating every 5 seconds.
      7. Confirm that once the scheduled task has finished in the terminal, the progress bar in the web page completes and stops polling.

      TESTING GARBAGE COLLECTION
      1. In your web browser navigate to `yourmoodle.com/admin/tool/testtasks/storedprogress.php` and confirm that you can see several progress bars from the previous test steps still listed there
      2. Login to the terminal of your web server
      3. Run the garbage collection scheduled task: `php admin/cli/scheduled_task.php --execute='\core\task\stored_progress_bar_cleanup_task`
      4. Confirm that any progress bars which were created 24+ hours ago have now been removed
      5. If you want to run this before the 24 hours, you can update the records in mdl_stored_progress and set the `timelastupdated` to 0 for any records you want to test cleaning up.

       

      TESTING CHANGING THE POLLING TIMEOUT

      1. Follow the instructions for one of the previous steps, to start a task running and navigate to the page to view them in the browser.
      2. In your config.php file add the line `$CFG->progresspollinterval = 10;`
      3. Navigate back to the progress bar view page (do not refresh) and confirm that the next time the bars are polled, it changes the timeout to check every 10 seconds instead of the default 5.
      4. Change it to some other values, or remove it entirely and confirm changes are applied in the browser.

       

      ADDING A STORED PROGRESS TO YOUR SCRIPT

      • See the code in admin/tool/testtasks/cli/stored_progress_watched_cli_script.php for a basic example of adding a stored progress bar to a script.
      • For adding to a scheduled/adhoc task, you can implement the trait `\core\task\stored_progress_task_trait`. See example tasks provided.
      Show
      Setup Install the testtasks admin tool on your moodle site: git clone https: //github .com /catalyst/moodle-tool_testtasks admin /tool/testtasks TESTING A SCHEDULED TASK 1. Login to the terminal of your web server 2. Run one of the example scheduled task scripts from the CLI: `php admin/cli/scheduled_task.php --execute='\tool_testtasks\task\stored_progress_scheduled_task_manual` `php admin/cli/scheduled_task.php --execute='\tool_testtasks\task\stored_progress_scheduled_task_iterations` This will start the task running, which will take some time. 3. Confirm in the database you can see the record created in mdl_stored_progress and that it is updating as the task progresses. 4. Whilst this is running, open your web browser and navigate to `yourmoodle.com/admin/tool/testtasks/storedprogress.php` this web page will show you all the running stored progress bars.  5. Confirm that you can see the progress bar and that it is updating every 5 seconds. 6. Note: The `stored_progress_scheduled_task_manual` task will fail with an error. This is intentional so you can confirm that the progress bar stops with an error. 7. Confirm that once the scheduled task has finished in the terminal, the progress bar in the web page completes and stops polling. 8. Note: You can check if the bar is still polling by checking the Network tab of your web browser and looking for web service requests for the `core_poll_stored_progress` web service. TESTING A SCHEDULED TASK ON THE EXISTING RUNNING-TASKS PAGE 1. Login to the terminal of your web server 2. Run one of the example scheduled task scripts from the CLI: `php admin/cli/scheduled_task.php --execute='local_example\task\stored_progress_scheduled_task_manual` `php admin/cli/scheduled_task.php --execute='local_example\task\stored_progress_scheduled_task_iterations` This will start the task running, which will take some time. 3. Confirm in the database you can see the record created in mdl_stored_progress and that it is updating as the task progresses. 4. Whilst this is running, navigate to Site Admin -> Server -> Tasks Running Now 5. Confirm that you can see the progress bar updating on this page whilst the task runs   TESTING AN ADHOC TASK 1. Login to the terminal of your web server 2. Run the following script to scheduled an adhoc task: `php admin/tool/testtasks/cli/schedule_stored_progress_adhoc_task.php`. This will create an adhoc task and give you the command to run to execute it. 3. Run the command you are given to execute the adhoc task. 4. Confirm in the database that you can see the record created in mdl_stored_progress and that it is updating as the task progresses. 5. Whilst this is running, open your web browser and navigate to `yourmoodle.com/admin/tool/testtasks/storedprogress.php` this web page will show you all the running stored progress bars.  6. Confirm that you can see the progress bar and that it is updating every 5 seconds. 7. Confirm that once the scheduled task has finished in the terminal, the progress bar in the web page completes and stops polling.   TESTING A CLI SCRIPT 1. Login to the terminal of your web server 2. Run the example script provided: `php admin/tool/testtasks/cli/stored_progress_watched_cli_script.php` 3. Confirm that the progress bar is displayed in the terminal and updates as it progresses 4. Confirm in the database that you can see the record created in mdl_stored_progress and that it is updating as the task progresses. 5. Whilst this is running, open your web browser and navigate to `yourmoodle.com/admin/tool/testtasks/storedprogress.php` this web page will show you all the running stored progress bars.  6. Confirm that you can see the progress bar and that it is updating every 5 seconds. 7. Confirm that once the scheduled task has finished in the terminal, the progress bar in the web page completes and stops polling. TESTING GARBAGE COLLECTION 1. In your web browser navigate to `yourmoodle.com/admin/tool/testtasks/storedprogress.php` and confirm that you can see several progress bars from the previous test steps still listed there 2. Login to the terminal of your web server 3. Run the garbage collection scheduled task: `php admin/cli/scheduled_task.php --execute='\core\task\stored_progress_bar_cleanup_task` 4. Confirm that any progress bars which were created 24+ hours ago have now been removed 5. If you want to run this before the 24 hours, you can update the records in mdl_stored_progress and set the `timelastupdated` to 0 for any records you want to test cleaning up.   TESTING CHANGING THE POLLING TIMEOUT Follow the instructions for one of the previous steps, to start a task running and navigate to the page to view them in the browser. In your config.php file add the line `$CFG->progresspollinterval = 10;` Navigate back to the progress bar view page (do not refresh) and confirm that the next time the bars are polled, it changes the timeout to check every 10 seconds instead of the default 5. Change it to some other values, or remove it entirely and confirm changes are applied in the browser.   ADDING A STORED PROGRESS TO YOUR SCRIPT See the code in admin/tool/testtasks/cli/stored_progress_watched_cli_script.php for a basic example of adding a stored progress bar to a script. For adding to a scheduled/adhoc task, you can implement the trait `\core\task\stored_progress_task_trait`. See example tasks provided.

      This should depend on MDL-65795 to provide a generic event bus to the client side. An example use case is when you have a long running task like am async backup, or language packs import (see also MDL-70608), and so we spawn an adhoc task but now you've lost all communication between the backend and front end so you cannot see any status.

      It would be very nice if there was a simple api where a task could be configured with an optional progress bar and the task api brokers the comms back through websockets to the front end so you can see what the task is doing right there. If you happen to reload the page you don't accidentally kill anything and it just the progress back up again from where it was.

            cwarwicker C Warwicker
            brendanheywood Brendan Heywood
            Brendan Heywood Brendan Heywood
            Jun Pataleta Jun Pataleta
            Votes:
            7 Vote for this issue
            Watchers:
            24 Start watching this issue

              Created:
              Updated:

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 6 hours, 8 minutes
                6h 8m

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