Skip to content

Commit

Permalink
fix: Changed ScheduledTaskEntity to enable automatic recovery for t…
Browse files Browse the repository at this point in the history
…asks stuck in state `running`. (shopware#5902)
  • Loading branch information
DrauzJu authored Dec 20, 2024
1 parent c98becd commit 0f74a84
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
title: improve-scheduled-task-recovery
issue: NEXT-00000
author: Julian Drauz
author_email: [email protected]
author_github: @DrauzJu
---
# Core
* Changed `ScheduledTaskEntity` to enable automatic recovery for tasks stuck in state `running`.
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,13 @@ public function getStatus(): string

public function isExecutionAllowed(): bool
{
// If the status is failed, skipped or queued, the execution is still allowed, so retries are possible
// If the status is failed, skipped or queued, the execution is still allowed, so retries are possible.
// To ensure idempotency, even allow execution if the task is currently running.
// The messenger transport must ensure no concurrent execution happens.
return $this->status === ScheduledTaskDefinition::STATUS_QUEUED
|| $this->status === ScheduledTaskDefinition::STATUS_FAILED
|| $this->status === ScheduledTaskDefinition::STATUS_SKIPPED;
|| $this->status === ScheduledTaskDefinition::STATUS_SKIPPED
|| $this->status === ScheduledTaskDefinition::STATUS_RUNNING;
}

public function setStatus(string $status): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public function testHandle(string $status): void
public static function allowedStatus(): array
{
return [
[ScheduledTaskDefinition::STATUS_RUNNING],
[ScheduledTaskDefinition::STATUS_QUEUED],
[ScheduledTaskDefinition::STATUS_FAILED],
];
Expand Down Expand Up @@ -265,7 +266,6 @@ public function testHandleIgnoresWhenTaskIsNotAllowedForExecution(string $status
public static function notAllowedStatus(): array
{
return [
[ScheduledTaskDefinition::STATUS_RUNNING],
[ScheduledTaskDefinition::STATUS_SCHEDULED],
[ScheduledTaskDefinition::STATUS_INACTIVE],
];
Expand Down

0 comments on commit 0f74a84

Please sign in to comment.