Skip to content

Commit c27fb28

Browse files
authored
Console command love:recount use default queue connection (#233)
1 parent 51f3d00 commit c27fb28

File tree

2 files changed

+9
-20
lines changed

2 files changed

+9
-20
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ All notable changes to `laravel-love` will be documented in this file.
1616
- ([#231]) Console command `love:setup-reactable` option `--nullable` replaced with `--not-nullable`
1717
- ([#231]) Console command `love:setup-reacterable` generates migration with nullable column `love_reacter_id` by default
1818
- ([#231]) Console command `love:setup-reacterable` option `--nullable` replaced with `--not-nullable`
19+
- ([#233]) Console command `love:recount` use default queue connection if `--queue-connection` option is not defined
1920
- ([#222]) Removed DI usage from console commands constructors
2021
- ([#215]) Migrated to console `AsCommand` attribute
2122
- ([#215]) Package generating anonymous class migrations now
@@ -567,6 +568,7 @@ Follow [upgrade instructions](UPGRADING.md#from-v5-to-v6) to migrate database to
567568
[1.1.1]: https://github.com/cybercog/laravel-love/compare/1.1.0...1.1.1
568569
[1.1.0]: https://github.com/cybercog/laravel-love/compare/1.0.0...1.1.0
569570

571+
[#233]: https://github.com/cybercog/laravel-love/pull/233
570572
[#231]: https://github.com/cybercog/laravel-love/pull/231
571573
[#222]: https://github.com/cybercog/laravel-love/pull/222
572574
[#218]: https://github.com/cybercog/laravel-love/pull/218

src/Console/Commands/Recount.php

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Cog\Laravel\Love\ReactionType\Models\ReactionType;
2121
use Illuminate\Console\Command;
2222
use Illuminate\Contracts\Bus\Dispatcher as DispatcherInterface;
23+
use Illuminate\Contracts\Config\Repository as AppConfigRepositoryInterface;
2324
use Illuminate\Database\Eloquent\Relations\Relation;
2425
use Symfony\Component\Console\Attribute\AsCommand;
2526
use Symfony\Component\Console\Input\InputOption;
@@ -62,6 +63,7 @@ protected function getOptions(): array
6263
*/
6364
public function handle(
6465
DispatcherInterface $dispatcher,
66+
AppConfigRepositoryInterface $appConfigRepository,
6567
): int {
6668
$this->dispatcher = $dispatcher;
6769

@@ -75,12 +77,15 @@ public function handle(
7577

7678
$queueConnectionName = $this->option('queue-connection');
7779
if ($queueConnectionName === null || $queueConnectionName === '') {
78-
$queueConnectionName = 'sync';
80+
$queueConnectionName = $appConfigRepository->get('queue.default');
7981
}
8082

83+
$this->warn(
84+
"Rebuilding reaction aggregates using `$queueConnectionName` queue connection."
85+
);
86+
8187
$reactants = $this->collectReactants($reactableType);
8288

83-
$this->warnProcessingStartedOn($queueConnectionName);
8489
$this->getOutput()->progressStart($reactants->count());
8590
foreach ($reactants as $reactant) {
8691
$this->dispatcher->dispatch(
@@ -166,22 +171,4 @@ private function collectReactants(
166171

167172
return $reactantsQuery->get();
168173
}
169-
170-
/**
171-
* Write warning output that processing has been started.
172-
*/
173-
private function warnProcessingStartedOn(
174-
?string $queueConnectionName,
175-
): void {
176-
if ($queueConnectionName === 'sync') {
177-
$message = 'Rebuilding reaction aggregates synchronously.';
178-
} else {
179-
$message = sprintf(
180-
'Adding rebuild reaction aggregates to the `%s` queue connection.',
181-
$queueConnectionName
182-
);
183-
}
184-
185-
$this->warn($message);
186-
}
187174
}

0 commit comments

Comments
 (0)