mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Add key to log messages context and add log prefix to enhance CancelStaleWorkflowHandler messages
Introduced a consistent LOG_PREFIX to all log messages in CancelStaleWorkflowHandler. This ensures clearer contextual identification in logs and improves traceability when debugging or monitoring workflow actions.
This commit is contained in:
parent
8ca377d5d4
commit
1d4ef19051
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]
|
||||
final readonly class CancelStaleWorkflowHandler
|
||||
{
|
||||
private const LOG_PREFIX = '[CancelStaleWorkflowHandler] ';
|
||||
|
||||
public function __construct(
|
||||
private EntityWorkflowRepository $workflowRepository,
|
||||
private Registry $registry,
|
||||
@ -40,13 +42,13 @@ final readonly class CancelStaleWorkflowHandler
|
||||
|
||||
$workflow = $this->workflowRepository->find($message->getWorkflowId());
|
||||
if (null === $workflow) {
|
||||
$this->logger->alert('Workflow was not found!', [$workflowId]);
|
||||
$this->logger->alert(self::LOG_PREFIX.'Workflow was not found!', ['entityWorkflowId' => $workflowId]);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
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');
|
||||
}
|
||||
@ -67,14 +69,14 @@ final readonly class CancelStaleWorkflowHandler
|
||||
'transitionAt' => $this->clock->now(),
|
||||
'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;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user