-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Melroy van den Berg <[email protected]>
- Loading branch information
1 parent
853e111
commit f1db652
Showing
9 changed files
with
109 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Message; | ||
|
||
use App\Message\Contracts\SchedulerInterface; | ||
|
||
class ClearDeadMessagesMessage implements SchedulerInterface | ||
{ | ||
public function __construct() | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Message; | ||
|
||
use App\Message\Contracts\SchedulerInterface; | ||
|
||
class ClearDeletedUserMessage implements SchedulerInterface | ||
{ | ||
public function __construct() | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Message\Contracts; | ||
|
||
interface SchedulerInterface extends MessageInterface | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\MessageHandler; | ||
|
||
use App\Message\ClearDeadMessagesMessage; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
use Doctrine\ORM\Query\ResultSetMapping; | ||
use Psr\Log\LoggerInterface; | ||
use Symfony\Component\Messenger\Attribute\AsMessageHandler; | ||
|
||
#[AsMessageHandler] | ||
class ClearDeadMessagesHandler | ||
{ | ||
public function __construct( | ||
private readonly EntityManagerInterface $entityManager, | ||
private readonly LoggerInterface $logger, | ||
) { | ||
} | ||
|
||
public function __invoke(ClearDeadMessagesMessage $message): void | ||
{ | ||
$this->logger->info('Clearing dead messages'); | ||
$sql = 'DELETE FROM messenger_messages WHERE queue_name = :queue_name'; | ||
$this->entityManager->createNativeQuery($sql, new ResultSetMapping()) | ||
->setParameter('queue_name', 'dead') | ||
->getResult(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Scheduler; | ||
|
||
use App\Message\ClearDeadMessagesMessage; | ||
use App\Message\ClearDeletedUserMessage; | ||
use Symfony\Component\Scheduler\Attribute\AsSchedule; | ||
use Symfony\Component\Scheduler\RecurringMessage; | ||
use Symfony\Component\Scheduler\Schedule; | ||
use Symfony\Component\Scheduler\ScheduleProviderInterface; | ||
use Symfony\Contracts\Cache\CacheInterface; | ||
|
||
#[AsSchedule] | ||
class MbinTaskProvider implements ScheduleProviderInterface | ||
{ | ||
private ?Schedule $schedule = null; | ||
|
||
public function __construct( | ||
private readonly CacheInterface $cache | ||
) { | ||
} | ||
|
||
public function getSchedule(): Schedule | ||
{ | ||
if (null === $this->schedule) { | ||
$this->schedule = (new Schedule()) | ||
->add( | ||
RecurringMessage::every('1 day', new ClearDeletedUserMessage()), | ||
RecurringMessage::every('1 day', new ClearDeadMessagesMessage()), | ||
) | ||
->stateful($this->cache); | ||
} | ||
|
||
return $this->schedule; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters