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

XMLWordPrintable

    • MOODLE_405_STABLE
    • MDL-70854-main
    • 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. Whilst this is running, navigate to Site Admin -> Server -> Tasks Running Now
      4. Confirm that you can see the progress bar and that it is updating every 5 seconds.
        • 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.
      5. Confirm that once the scheduled task has finished in the terminal, the progress bar on the web page completes and stops polling.
        • 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_output_poll_stored_progress` web service.
      TESTING AN ADHOC TASK
      1. Login to the terminal of your web server
      2. Run the following script to schedule an ad-hoc task: `php admin/tool/testtasks/cli/schedule_stored_progress_adhoc_task.php`. This will create an ad hoc task and give you the command to run and execute it.
      3. Run the command you are given to execute the ad-hoc task.
      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. Confirm that once the scheduled task has finished in the terminal, the progress bar on 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. 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. Confirm that once the scheduled task has finished in the terminal, the progress bar on 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. Edit some of the database records in the stored_progress table and set the "lastupdate" value to a timestamp that is more than 24 hours ago. (or use this: 1721641234). Take note of the value of the message column of the records that you edited.
      3. Login to the terminal of your web server.
      4. Run the garbage collection scheduled task: php admin/cli/scheduled_task.php --execute='\core\task\stored_progress_bar_cleanup_task'
      5. Confirm that any progress bars that were created 24+ hours ago have now been removed
      TESTING CHANGING THE POLLING TIMEOUT
      1. Run the "\tool_testtasks\task\stored_progress_scheduled_task_iterations}} scheduled task.
      2. Navigate to "admin/tool/testtasks/storedprogress.php" to view the task.
      3. In your config.php file add the line `$CFG->progresspollinterval = 10;`
      4. 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.
      5. Change it to some other values, or remove it entirely and confirm changes are applied in the browser.
      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 Login to the terminal of your web server 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. Whilst this is running, navigate to Site Admin -> Server -> Tasks Running Now Confirm that you can see the progress bar and that it is updating every 5 seconds. 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. Confirm that once the scheduled task has finished in the terminal, the progress bar on the web page completes and stops polling. 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_output_poll_stored_progress` web service. TESTING AN ADHOC TASK Login to the terminal of your web server Run the following script to schedule an ad-hoc task: `php admin/tool/testtasks/cli/schedule_stored_progress_adhoc_task.php`. This will create an ad hoc task and give you the command to run and execute it. Run the command you are given to execute the ad-hoc task. 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.  Confirm that you can see the progress bar and that it is updating every 5 seconds. Confirm that once the scheduled task has finished in the terminal, the progress bar on the web page completes and stops polling. TESTING A CLI SCRIPT Login to the terminal of your web server Run the example script provided: `php admin/tool/testtasks/cli/stored_progress_watched_cli_script.php` Confirm that the progress bar is displayed in the terminal and updates as it progresses 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.  Confirm that you can see the progress bar and that it is updating every 5 seconds. Confirm that once the scheduled task has finished in the terminal, the progress bar on the web page completes and stops polling. TESTING GARBAGE COLLECTION 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 Edit some of the database records in the stored_progress table and set the " lastupdate " value to a timestamp that is more than 24 hours ago. (or use this: 1721641234). Take note of the value of the message column of the records that you edited. Login to the terminal of your web server. Run the garbage collection scheduled task: php admin/cli/scheduled_task.php --execute='\core\task\stored_progress_bar_cleanup_task' Confirm that any progress bars that were created 24+ hours ago have now been removed TESTING CHANGING THE POLLING TIMEOUT Run the "\tool_testtasks\task\stored_progress_scheduled_task_iterations}} scheduled task. Navigate to " admin/tool/testtasks/storedprogress.php " to view the task. 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.

      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.

        1. image-2024-01-31-10-57-25-641.png
          image-2024-01-31-10-57-25-641.png
          11 kB
        2. MDL-70854.png
          MDL-70854.png
          581 kB
        3. MDL-70854 - 2.png
          MDL-70854 - 2.png
          365 kB
        4. MDL-70854 -3.png
          MDL-70854 -3.png
          345 kB
        5. MDL-70854 - 4.png
          MDL-70854 - 4.png
          244 kB
        6. MDL-70854 - 5.png
          MDL-70854 - 5.png
          411 kB

            cwarwicker C Warwicker
            brendanheywood Brendan Heywood
            Brendan Heywood Brendan Heywood
            Jun Pataleta Jun Pataleta
            Ron Carl Alfon Yu Ron Carl Alfon Yu
            Votes:
            7 Vote for this issue
            Watchers:
            26 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 day, 51 minutes
                1d 51m

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