mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Php cs fixes
This commit is contained in:
parent
35199b6993
commit
5d84e997c1
@ -1,12 +1,19 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Service\Workflow;
|
||||
|
||||
class CancelStaleWorkflow
|
||||
{
|
||||
public function __construct(public int $workflowId)
|
||||
{
|
||||
}
|
||||
public function __construct(public int $workflowId) {}
|
||||
|
||||
public function getWorkflowId(): int
|
||||
{
|
||||
|
@ -1,11 +1,19 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Service\Workflow;
|
||||
|
||||
use Chill\MainBundle\Cron\CronJobInterface;
|
||||
use Chill\MainBundle\Entity\CronJobExecution;
|
||||
use Chill\MainBundle\Repository\Workflow\EntityWorkflowRepository;
|
||||
use DateInterval;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\Clock\ClockInterface;
|
||||
use Symfony\Component\Messenger\MessageBusInterface;
|
||||
@ -18,17 +26,16 @@ class CancelStaleWorkflowCronJob implements CronJobInterface
|
||||
|
||||
private const string LAST_CANCELED_WORKFLOW = 'last-canceled-workflow-id';
|
||||
|
||||
public function __construct(private readonly EntityWorkflowRepository $workflowRepository,
|
||||
public function __construct(
|
||||
private readonly EntityWorkflowRepository $workflowRepository,
|
||||
private readonly ClockInterface $clock,
|
||||
private readonly MessageBusInterface $messageBus,
|
||||
private readonly LoggerInterface $logger,
|
||||
)
|
||||
{
|
||||
}
|
||||
) {}
|
||||
|
||||
public function canRun(?CronJobExecution $cronJobExecution): bool
|
||||
{
|
||||
return $this->clock->now() >= $cronJobExecution->getLastEnd()->add(new DateInterval('P1D'));
|
||||
return $this->clock->now() >= $cronJobExecution->getLastEnd()->add(new \DateInterval('P1D'));
|
||||
}
|
||||
|
||||
public function getKey(): string
|
||||
@ -40,7 +47,7 @@ class CancelStaleWorkflowCronJob implements CronJobInterface
|
||||
{
|
||||
$this->logger->info('Cronjob started: Canceling stale workflows.');
|
||||
|
||||
$olderThanDate = $this->clock->now()->sub(new DateInterval(self::KEEP_INTERVAL));
|
||||
$olderThanDate = $this->clock->now()->sub(new \DateInterval(self::KEEP_INTERVAL));
|
||||
$staleWorkflowIds = $this->workflowRepository->findWorkflowsWithoutFinalStepAndOlderThan($olderThanDate);
|
||||
$lastCanceled = self::LAST_CANCELED_WORKFLOW;
|
||||
$processedCount = 0;
|
||||
@ -49,7 +56,7 @@ class CancelStaleWorkflowCronJob implements CronJobInterface
|
||||
try {
|
||||
$this->messageBus->dispatch(new CancelStaleWorkflow($wId));
|
||||
$lastCanceled = $wId;
|
||||
$processedCount++;
|
||||
++$processedCount;
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->error("Failed to dispatch CancelStaleWorkflow for ID {$wId}", ['exception' => $e]);
|
||||
continue;
|
||||
|
@ -1,5 +1,14 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Service\Workflow;
|
||||
|
||||
use Chill\MainBundle\Repository\Workflow\EntityWorkflowRepository;
|
||||
@ -12,9 +21,7 @@ use Symfony\Component\Workflow\Registry;
|
||||
#[AsMessageHandler]
|
||||
class CancelStaleWorkflowHandler
|
||||
{
|
||||
public function __construct(private readonly EntityWorkflowRepository $workflowRepository, private readonly Registry $registry, private EntityManagerInterface $em, private LoggerInterface $logger)
|
||||
{
|
||||
}
|
||||
public function __construct(private readonly EntityWorkflowRepository $workflowRepository, private readonly Registry $registry, private EntityManagerInterface $em, private LoggerInterface $logger) {}
|
||||
|
||||
public function __invoke(CancelStaleWorkflow $message): void
|
||||
{
|
||||
@ -28,7 +35,7 @@ class CancelStaleWorkflowHandler
|
||||
|
||||
$transitionApplied = false;
|
||||
|
||||
if (count($steps) === 1) {
|
||||
if (1 === count($steps)) {
|
||||
$this->em->remove($workflow->getCurrentStep());
|
||||
$this->em->remove($workflow);
|
||||
} else {
|
||||
@ -46,12 +53,8 @@ class CancelStaleWorkflowHandler
|
||||
|
||||
if (!$transitionApplied) {
|
||||
$this->logger->error(sprintf('No valid transition found for EntityWorkflow %d.', $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));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -23,6 +23,11 @@ use Symfony\Component\Clock\MockClock;
|
||||
use Symfony\Component\Messenger\Envelope;
|
||||
use Symfony\Component\Messenger\MessageBusInterface;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @coversNothing
|
||||
*/
|
||||
class CancelStaleWorkflowCronJobTest extends KernelTestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
@ -33,6 +38,7 @@ class CancelStaleWorkflowCronJobTest extends KernelTestCase
|
||||
|
||||
/**
|
||||
* @dataProvider buildTestCanRunData
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function testCanRun(?CronJobExecution $cronJobExecution, bool $expected): void
|
||||
|
@ -1,5 +1,14 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Services\Workflow;
|
||||
|
||||
use Chill\MainBundle\Entity\Workflow\EntityWorkflow;
|
||||
@ -15,9 +24,13 @@ use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException;
|
||||
use Symfony\Component\Workflow\Metadata\MetadataStoreInterface;
|
||||
use Symfony\Component\Workflow\Registry;
|
||||
use Symfony\Component\Workflow\Transition;
|
||||
use Symfony\Component\Workflow\Workflow;
|
||||
use Symfony\Component\Workflow\WorkflowInterface;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @coversNothing
|
||||
*/
|
||||
class CancelStaleWorkflowHandlerTest extends TestCase
|
||||
{
|
||||
public function testInvokeWorkflowWithOneStep(): void
|
||||
|
Loading…
x
Reference in New Issue
Block a user