mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Merge branch 'fix/cancel-stale-workflow-handle-fails-silently' into 'master'
Add consistent LOG_PREFIX and key to CancelStaleWorkflowHandler logs See merge request Chill-Projet/chill-bundles!817
This commit is contained in:
commit
cc7e7a90ee
6
.changes/unreleased/Fixed-20250416-210315.yaml
Normal file
6
.changes/unreleased/Fixed-20250416-210315.yaml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
kind: Fixed
|
||||||
|
body: Add consistent log prefix and key to logs when stale workflows are automatically canceled
|
||||||
|
time: 2025-04-16T21:03:15.491889784+02:00
|
||||||
|
custom:
|
||||||
|
Issue: ""
|
||||||
|
SchemaChange: No schema change
|
@ -25,6 +25,8 @@ use Symfony\Component\Workflow\Transition;
|
|||||||
#[AsMessageHandler]
|
#[AsMessageHandler]
|
||||||
final readonly class CancelStaleWorkflowHandler
|
final readonly class CancelStaleWorkflowHandler
|
||||||
{
|
{
|
||||||
|
private const LOG_PREFIX = '[CancelStaleWorkflowHandler] ';
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private EntityWorkflowRepository $workflowRepository,
|
private EntityWorkflowRepository $workflowRepository,
|
||||||
private Registry $registry,
|
private Registry $registry,
|
||||||
@ -40,13 +42,13 @@ final readonly class CancelStaleWorkflowHandler
|
|||||||
|
|
||||||
$workflow = $this->workflowRepository->find($message->getWorkflowId());
|
$workflow = $this->workflowRepository->find($message->getWorkflowId());
|
||||||
if (null === $workflow) {
|
if (null === $workflow) {
|
||||||
$this->logger->alert('Workflow was not found!', [$workflowId]);
|
$this->logger->alert(self::LOG_PREFIX.'Workflow was not found!', ['entityWorkflowId' => $workflowId]);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (false === $workflow->isStaledAt($olderThanDate)) {
|
if (false === $workflow->isStaledAt($olderThanDate)) {
|
||||||
$this->logger->alert('Workflow has transitioned in the meantime.', [$workflowId]);
|
$this->logger->alert(self::LOG_PREFIX.'Workflow has transitioned in the meantime.', ['entityWorkflowId' => $workflowId]);
|
||||||
|
|
||||||
throw new UnrecoverableMessageHandlingException('the workflow is not staled any more');
|
throw new UnrecoverableMessageHandlingException('the workflow is not staled any more');
|
||||||
}
|
}
|
||||||
@ -67,14 +69,14 @@ final readonly class CancelStaleWorkflowHandler
|
|||||||
'transitionAt' => $this->clock->now(),
|
'transitionAt' => $this->clock->now(),
|
||||||
'transition' => $transition->getName(),
|
'transition' => $transition->getName(),
|
||||||
]);
|
]);
|
||||||
$this->logger->info('EntityWorkflow has been cancelled automatically.', [$workflowId]);
|
$this->logger->info(self::LOG_PREFIX.'EntityWorkflow has been cancelled automatically.', ['entityWorkflowId' => $workflowId]);
|
||||||
$transitionApplied = true;
|
$transitionApplied = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$transitionApplied) {
|
if (!$transitionApplied) {
|
||||||
$this->logger->error('No valid transition found for EntityWorkflow.', [$workflowId]);
|
$this->logger->error(self::LOG_PREFIX.'No valid transition found for EntityWorkflow.', ['entityWorkflowId' => $workflowId]);
|
||||||
throw new UnrecoverableMessageHandlingException(sprintf('No valid transition found for EntityWorkflow %d.', $workflowId));
|
throw new UnrecoverableMessageHandlingException(sprintf('No valid transition found for EntityWorkflow %d.', $workflowId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user