Skip to content

Commit

Permalink
ProcessJobCommand - make health check TTL configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
burithetech committed Sep 4, 2024
1 parent 14aa911 commit e20ae93
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p

## [Unreleased]

### [Mailer]

- Added ability to set custom health check TTL for `ProcessJobCommand`. remp/remp#1376

## Archive

Expand Down
23 changes: 10 additions & 13 deletions Mailer/extensions/mailer-module/src/Commands/ProcessJobCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,14 @@
class ProcessJobCommand extends Command
{
public const COMMAND_NAME = "mail:process-job";

private $batchesRepository;

private $batchEmailGenerator;

private HealthChecker $healthChecker;
private int $healthCheckTTLSeconds = 600;

public function __construct(
BatchesRepository $batchesRepository,
BatchEmailGenerator $batchEmailGenerator,
HealthChecker $healthChecker
private readonly BatchesRepository $batchesRepository,
private readonly BatchEmailGenerator $batchEmailGenerator,
private readonly HealthChecker $healthChecker,
) {
parent::__construct();
$this->batchesRepository = $batchesRepository;
$this->batchEmailGenerator = $batchEmailGenerator;
$this->healthChecker = $healthChecker;
}

protected function configure(): void
Expand All @@ -51,7 +43,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
while ($batch = $this->batchesRepository->getBatchReady()) {
$originalStatus = $batch->status;
try {
$this->healthChecker->ping(self::COMMAND_NAME, 600);
$this->healthChecker->ping(self::COMMAND_NAME, $this->healthCheckTTLSeconds);

$this->batchesRepository->updateStatus($batch, BatchesRepository::STATUS_PROCESSING);
$output->writeln(" * processing mail batch <info>#{$batch->id}</info>");
Expand Down Expand Up @@ -92,4 +84,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int

return Command::SUCCESS;
}

public function setHealthCheckTTLSeconds(int $seconds): void
{
$this->healthCheckTTLSeconds = $seconds;
}
}
4 changes: 3 additions & 1 deletion Mailer/extensions/mailer-module/src/config/config.neon
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ services:

redisClientFactory: Remp\MailerModule\Models\RedisClientFactory(%redis.host%, %redis.port%, %redis.db%, %redis.password%, %redis_client_factory.prefix%)

processJobCommand: Remp\MailerModule\Commands\ProcessJobCommand()

console:
factory: Symfony\Component\Console\Application
setup:
- add(Remp\MailerModule\Commands\ProcessJobCommand())
- add(@processJobCommand)
- add(@mailWorkerCommand)
- add(Remp\MailerModule\Commands\DatabaseSeedCommand())
- add(Remp\MailerModule\Commands\DemoSeedCommand())
Expand Down

0 comments on commit e20ae93

Please sign in to comment.