Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Console command love:recount use default queue connection #233

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ All notable changes to `laravel-love` will be documented in this file.
- ([#231]) Console command `love:setup-reactable` option `--nullable` replaced with `--not-nullable`
- ([#231]) Console command `love:setup-reacterable` generates migration with nullable column `love_reacter_id` by default
- ([#231]) Console command `love:setup-reacterable` option `--nullable` replaced with `--not-nullable`
- ([#233]) Console command `love:recount` use default queue connection if `--queue-connection` option is not defined
- ([#222]) Removed DI usage from console commands constructors
- ([#215]) Migrated to console `AsCommand` attribute
- ([#215]) Package generating anonymous class migrations now
Expand Down Expand Up @@ -567,6 +568,7 @@ Follow [upgrade instructions](UPGRADING.md#from-v5-to-v6) to migrate database to
[1.1.1]: https://github.com/cybercog/laravel-love/compare/1.1.0...1.1.1
[1.1.0]: https://github.com/cybercog/laravel-love/compare/1.0.0...1.1.0

[#233]: https://github.com/cybercog/laravel-love/pull/233
[#231]: https://github.com/cybercog/laravel-love/pull/231
[#222]: https://github.com/cybercog/laravel-love/pull/222
[#218]: https://github.com/cybercog/laravel-love/pull/218
Expand Down
27 changes: 7 additions & 20 deletions src/Console/Commands/Recount.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Cog\Laravel\Love\ReactionType\Models\ReactionType;
use Illuminate\Console\Command;
use Illuminate\Contracts\Bus\Dispatcher as DispatcherInterface;
use Illuminate\Contracts\Config\Repository as AppConfigRepositoryInterface;
use Illuminate\Database\Eloquent\Relations\Relation;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputOption;
Expand Down Expand Up @@ -62,6 +63,7 @@ protected function getOptions(): array
*/
public function handle(
DispatcherInterface $dispatcher,
AppConfigRepositoryInterface $appConfigRepository,
): int {
$this->dispatcher = $dispatcher;

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

$queueConnectionName = $this->option('queue-connection');
if ($queueConnectionName === null || $queueConnectionName === '') {
$queueConnectionName = 'sync';
$queueConnectionName = $appConfigRepository->get('queue.default');
}

$this->warn(
"Rebuilding reaction aggregates using `$queueConnectionName` queue connection."
);

$reactants = $this->collectReactants($reactableType);

$this->warnProcessingStartedOn($queueConnectionName);
$this->getOutput()->progressStart($reactants->count());
foreach ($reactants as $reactant) {
$this->dispatcher->dispatch(
Expand Down Expand Up @@ -166,22 +171,4 @@ private function collectReactants(

return $reactantsQuery->get();
}

/**
* Write warning output that processing has been started.
*/
private function warnProcessingStartedOn(
?string $queueConnectionName,
): void {
if ($queueConnectionName === 'sync') {
$message = 'Rebuilding reaction aggregates synchronously.';
} else {
$message = sprintf(
'Adding rebuild reaction aggregates to the `%s` queue connection.',
$queueConnectionName
);
}

$this->warn($message);
}
}