Skip to content

Commit b02ab50

Browse files
committed
fix: unify stale job timeout and expose as config setting
1 parent f82161d commit b02ab50

6 files changed

Lines changed: 17 additions & 10 deletions

File tree

Classes/Command/SchedulerCommandController.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,11 @@ public function injectConnection(Connection $connection): void
5454
* Reset stale jobs that have not changed for too long.
5555
*
5656
* @param string $groupName Free jobs in this group only
57-
* @param int $minutes Count jobs as stale if their last activity was more than these many minutes ago
58-
* @throws Exception
5957
*/
6058
public function resetStaleJobsCommand(
6159
string $groupName,
62-
int $minutes = 10
6360
): void {
64-
$freed = $this->scheduler->resetStaleJobs($groupName, $minutes);
61+
$freed = $this->scheduler->resetStaleJobs($groupName);
6562
if ($freed) {
6663
$this->outputLine('Freed ' . $freed . ' stale jobs.');
6764
}

Classes/Domain/AbstractScheduler.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ abstract class AbstractScheduler implements Scheduler
3737
*/
3838
protected TimeBaseForDueDateCalculation $timeBaseForDueDateCalculation;
3939

40+
#[Flow\InjectConfiguration(path: 'staleJobTimeout')]
41+
protected int $staleJobTimeoutSecs;
42+
4043
protected const CLAIM_QUERY = "";
4144
protected const SELECT_QUERY = "";
4245
protected const RELEASE_QUERY = "";
@@ -280,16 +283,15 @@ public function activity(ScheduledJob $job): void
280283
* Reset stale jobs that have not changed for too long.
281284
*
282285
* @param string $groupName Free jobs in this group only
283-
* @param int $minutes Count jobs as stale if their last activity was more than these many minutes ago
284286
* @throws Exception
285287
* @return int Number of freed jobs
286288
*/
287-
public function resetStaleJobs(string $groupName, int $minutes): int {
289+
public function resetStaleJobs(string $groupName): int {
288290
return $this->dbal->executeQuery(
289291
sql: static::RESET_STALE_JOBS_QUERY,
290292
params: [
291293
'groupName' => $groupName,
292-
'minutes' => max($minutes, 1),
294+
'seconds' => max($this->staleJobTimeoutSecs, 1),
293295
],
294296
types: [
295297
'groupName' => Types::STRING,

Classes/Domain/MySQLScheduler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class MySQLScheduler extends AbstractScheduler {
118118
WHERE running = 1
119119
AND claimed NOT LIKE 'failed(%)'
120120
AND groupname = :groupName
121-
AND activity < NOW() - INTERVAL :minutes MINUTE
121+
AND activity < NOW() - INTERVAL :seconds SECOND
122122
MySQL;
123123

124124
}

Classes/Domain/PostgreSQLScheduler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class PostgreSQLScheduler extends AbstractScheduler {
8383
WHERE running = 1
8484
AND claimed NOT LIKE 'failed(%)'
8585
AND groupname = :groupName
86-
AND activity < NOW() - make_interval(mins => :minutes)
86+
AND activity < NOW() - make_interval(secs => :seconds)
8787
PostgreSQL;
8888

8989
}

Classes/Domain/Scheduler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function fail(ScheduledJob $job, string $reason): void;
2323

2424
public function activity(ScheduledJob $job): void;
2525

26-
public function resetStaleJobs(string $groupName, int $minutes): int;
26+
public function resetStaleJobs(string $groupName): int;
2727

2828
public function getConnection(): Connection;
2929
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Netlogix:
2+
JobQueue:
3+
Scheduled:
4+
5+
# Time (in seconds) of inactivity (no updates to the jobs activity timestamp column) after which a job
6+
# is considered stale and needs to be reset (see SchedulerCommandController::resetStaleJobsCommand)
7+
# in order to be picked up again.
8+
staleJobTimeout: 60

0 commit comments

Comments
 (0)