File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -352,6 +352,10 @@ public static function run_adhoc_task(int $taskid): void {
352352 /**
353353 * Execute all failed adhoc tasks.
354354 *
355+ * This includes tasks that have exhausted their retry limits.
356+ * It is intended for manual intervention from CLI or UI scripts,
357+ * matching the behaviour of manually triggering individual failed tasks.
358+ *
355359 * @param string|null $classname Run only tasks of this class
356360 */
357361 public static function run_failed_adhoc_tasks (?string $ classname = null ): void {
@@ -364,8 +368,6 @@ public static function run_failed_adhoc_tasks(?string $classname = null): void {
364368 $ params ['classname ' ] = \core \task \manager::get_canonical_class_name ($ classname );
365369 }
366370
367- // Only rerun the failed tasks that allow to be re-tried or have the remaining attempts available.
368- $ where .= ' AND (attemptsavailable > 0 OR attemptsavailable IS NULL) ' ;
369371 $ tasks = $ DB ->get_records_sql ("SELECT * from {task_adhoc} WHERE $ where " , $ params );
370372 foreach ($ tasks as $ t ) {
371373 self ::run_adhoc_task ($ t ->id );
Original file line number Diff line number Diff line change @@ -154,4 +154,32 @@ public function test_setup_user(): void {
154154
155155 // phpcs:enable
156156 }
157+
158+ /**
159+ * Test running failed adhoc tasks ignores the attemptsavailable filter.
160+ */
161+ public function test_run_failed_adhoc_tasks (): void {
162+ global $ DB ;
163+ $ this ->resetAfterTest ();
164+
165+ require_once (__DIR__ . '/fixtures/task_fixtures.php ' );
166+
167+ // Create a standard test task.
168+ $ task = new \core \task \adhoc_test_task ();
169+ \core \task \manager::queue_adhoc_task ($ task );
170+
171+ // Force it into an exhausted, failed state.
172+ $ DB ->set_field ('task_adhoc ' , 'faildelay ' , 60 );
173+ $ DB ->set_field ('task_adhoc ' , 'attemptsavailable ' , 0 );
174+
175+ $ this ->assertEquals (1 , $ DB ->count_records ('task_adhoc ' ));
176+
177+ // Silence the output of the CLI runner.
178+ ob_start ();
179+ cron::run_failed_adhoc_tasks ();
180+ ob_end_clean ();
181+
182+ // The task should have run and been deleted.
183+ $ this ->assertEquals (0 , $ DB ->count_records ('task_adhoc ' ));
184+ }
157185}
You can’t perform that action at this time.
0 commit comments