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

Extend Clean up ad hoc task metadata logging and run it more frequently

    • MOODLE_401_STABLE, MOODLE_402_STABLE, MOODLE_403_STABLE
    • MDL-78437-cleanup-metadata
    • Hide

      Prerequisites

      1. Install tool_testtasks:

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

      2. Modify this patch so tasks get cleaned up quicker:
        1. Open lib/classes/task/manager.php
        2. In the cleanup_metadata method, look for:

          if ($runningtask->timestarted > time() - HOURSECS) {
              continue;
          }
          

        3. Modify it to:

          if ($runningtask->timestarted > time() - MINSECS) {
              continue;
          }
          

      Testing

      1. Browse to "Site administration" > "Server" > "Tasks running now" (you'll need to get back to this page quickly after the next steps)
      2. Queue up 1 1000 second tasks:

        php admin/tool/testtasks/cli/queue_multiple_adhoc_tasks.php -n=1 -c="tool_testtasks\task\one_thousand_second_task"

      3. Start processing the task:

        php admin/cli/adhoc_task.php -e

      4. Kill the adhoc task runners in the terminal by pressing ctrl+z followed by the command: kill -9 %1
      5. Refresh the "Tasks running now page" and verify you see 1000 second task processing
      6. Run the cleanup task:

        php admin/cli/scheduled_task.php --execute=\\core\\task\\task_lock_cleanup_task 

      7. Verify the output contains "Marking orphaned adhoc task as failed: tool_testtasks\task\one_thousand_second_task (adhoc task id x)
      Show
      Prerequisites Install tool_testtasks: git clone git@github.com:catalyst/moodle-tool_testtasks.git admin/tool/testtasks Modify this patch so tasks get cleaned up quicker: Open lib/classes/task/manager.php In the cleanup_metadata method, look for: if ($runningtask->timestarted > time() - HOURSECS) { continue; } Modify it to: if ($runningtask->timestarted > time() - MINSECS) { continue; } Testing Browse to "Site administration" > "Server" > "Tasks running now" (you'll need to get back to this page quickly after the next steps) Queue up 1 1000 second tasks: php admin/tool/testtasks/cli/queue_multiple_adhoc_tasks.php -n=1 -c="tool_testtasks\task\one_thousand_second_task" Start processing the task: php admin/cli/adhoc_task.php -e Kill the adhoc task runners in the terminal by pressing ctrl+z followed by the command: kill -9 %1 Refresh the "Tasks running now page" and verify you see 1000 second task processing Run the cleanup task: php admin/cli/scheduled_task.php --execute=\\core\\task\\task_lock_cleanup_task Verify the output contains "Marking orphaned adhoc task as failed: tool_testtasks\task\one_thousand_second_task (adhoc task id x)
    • Hide

      Code verified against automated checks with warnings.

      Checked MDL-78437 using repository: https://github.com/bwalkerl/moodle

      Should these errors be fixed?

      Built on: Thu Apr 3 01:46:33 UTC 2025

      Show
      Code verified against automated checks with warnings. Checked MDL-78437 using repository: https://github.com/bwalkerl/moodle main (0 errors / 2 warnings) [branch: MDL-78437-cleanup-metadata | CI Job ] overview (0/0) , phplint (0/0) , phpcs (0/0) , js (0/0) , css (0/0) , phpdoc (0/0) , commit (0/2) , savepoint (0/0) , thirdparty (0/0) , externalbackup (0/0) , grunt (0/0) , shifter (0/0) , mustache (0/0) , gherkin (0/0) , Should these errors be fixed? Built on: Thu Apr 3 01:46:33 UTC 2025
    • Show
      Launching automatic jobs for branch MDL-78437 -cleanup-metadata https://ci.moodle.org/view/Testing/job/DEV.02%20-%20Developer-requested%20PHPUnit/18906/ PHPUnit (sqlsrv) https://ci.moodle.org/view/Testing/job/DEV.01%20-%20Developer-requested%20Behat/64723/ Behat (NonJS - boost and classic) https://ci.moodle.org/view/Testing/job/DEV.01%20-%20Developer-requested%20Behat/64724/ Behat (Firefox - boost) https://ci.moodle.org/view/Testing/job/DEV.01%20-%20Developer-requested%20Behat/64725/ Behat (Firefox - classic) https://ci.moodle.org/view/Testing/job/DEV.01%20-%20Developer-requested%20Behat/64726/ App tests (stable app version) Built on: Thu Apr 3 02:25:15 UTC 2025

      The "Clean up ad hoc task metadata" (task_lock_cleanup_task) is doing a great job. However, in some environments where cron containers may be re-rolled automatically there is a need to run this task more frequently to release locks quicker.

      The task is pretty cheap so it may be executed every 5-10 mins without any overhead.

      Also, it would be good to extend its logging and write down the list of task locks it could release. This will give some statistics on how often this happens.

            benjaminwalker Benjamin Walker
            mikhailgolenkov Misha Golenkov
            Brendan Heywood Brendan Heywood
            Votes:
            3 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:

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