Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6070151

Browse files
minor #30800 [Messenger] fix review (nicolas-grekas)
This PR was merged into the 4.3-dev branch. Discussion ---------- [Messenger] fix review | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Fixes my review left in #30754 /cc @weaverryan FYI Commits ------- a3de902 [Messenger] fix review
2 parents a9459c0 + a3de902 commit 6070151

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/Symfony/Component/Messenger/Command/StopWorkersCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ protected function execute(InputInterface $input, OutputInterface $output): void
6565
$io = new SymfonyStyle($input, $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output);
6666

6767
$cacheItem = $this->restartSignalCachePool->getItem(StopWhenRestartSignalIsReceived::RESTART_REQUESTED_TIMESTAMP_KEY);
68-
$cacheItem->set(time());
68+
$cacheItem->set(microtime(true));
6969
$this->restartSignalCachePool->save($cacheItem);
7070

7171
$io->success('Signal successfully sent to stop any running workers.');

src/Symfony/Component/Messenger/Worker/StopWhenRestartSignalIsReceived.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ public function __construct(WorkerInterface $decoratedWorker, CacheItemPoolInter
3838

3939
public function run(array $options = [], callable $onHandledCallback = null): void
4040
{
41-
$workerStartedTimestamp = time();
41+
$workerStartedAt = microtime(true);
4242

43-
$this->decoratedWorker->run($options, function (?Envelope $envelope) use ($onHandledCallback, $workerStartedTimestamp) {
43+
$this->decoratedWorker->run($options, function (?Envelope $envelope) use ($onHandledCallback, $workerStartedAt) {
4444
if (null !== $onHandledCallback) {
4545
$onHandledCallback($envelope);
4646
}
4747

48-
if ($this->shouldRestart($workerStartedTimestamp)) {
48+
if ($this->shouldRestart($workerStartedAt)) {
4949
$this->stop();
5050
if (null !== $this->logger) {
5151
$this->logger->info('Worker stopped because a restart was requested.');
@@ -59,9 +59,10 @@ public function stop(): void
5959
$this->decoratedWorker->stop();
6060
}
6161

62-
private function shouldRestart(int $workerStartedAt)
62+
private function shouldRestart(float $workerStartedAt)
6363
{
6464
$cacheItem = $this->cachePool->getItem(self::RESTART_REQUESTED_TIMESTAMP_KEY);
65+
6566
if (!$cacheItem->isHit()) {
6667
// no restart has ever been scheduled
6768
return false;

0 commit comments

Comments
 (0)