From 251cf5848f5838bb47be3e35e5116d14de9232a5 Mon Sep 17 00:00:00 2001 From: Anton Komarev Date: Sun, 8 Jan 2023 14:05:55 +0300 Subject: [PATCH 1/4] Console command love:recount use default queue connection if option not defined --- CHANGELOG.md | 1 + src/Console/Commands/Recount.php | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f8e090b7..9efca8e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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` +- 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 diff --git a/src/Console/Commands/Recount.php b/src/Console/Commands/Recount.php index b62a0a36..6cea31af 100644 --- a/src/Console/Commands/Recount.php +++ b/src/Console/Commands/Recount.php @@ -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; @@ -62,6 +63,7 @@ protected function getOptions(): array */ public function handle( DispatcherInterface $dispatcher, + AppConfigRepositoryInterface $appConfigRepository, ): int { $this->dispatcher = $dispatcher; @@ -75,7 +77,7 @@ public function handle( $queueConnectionName = $this->option('queue-connection'); if ($queueConnectionName === null || $queueConnectionName === '') { - $queueConnectionName = 'sync'; + $queueConnectionName = $appConfigRepository->get('queue.default'); } $reactants = $this->collectReactants($reactableType); From 7bfe06171ddf1eb23884f502c0adb991a12df58a Mon Sep 17 00:00:00 2001 From: Anton Komarev Date: Sun, 8 Jan 2023 14:10:08 +0300 Subject: [PATCH 2/4] Update changelog --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9efca8e0..88be23cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,7 +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` -- Console command `love:recount` use default queue connection if `--queue-connection` option is not defined +- ([#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 @@ -568,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 From 766061c216abd91c8efeb1db30abeabeb06e7b1d Mon Sep 17 00:00:00 2001 From: Anton Komarev Date: Sun, 8 Jan 2023 14:15:16 +0300 Subject: [PATCH 3/4] WIP --- src/Console/Commands/Recount.php | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/src/Console/Commands/Recount.php b/src/Console/Commands/Recount.php index 6cea31af..131ecfa9 100644 --- a/src/Console/Commands/Recount.php +++ b/src/Console/Commands/Recount.php @@ -82,7 +82,10 @@ public function handle( $reactants = $this->collectReactants($reactableType); - $this->warnProcessingStartedOn($queueConnectionName); + $this->warn( + "Rebuilding reaction aggregates using `$queueConnectionName` queue connection." + ); + $this->getOutput()->progressStart($reactants->count()); foreach ($reactants as $reactant) { $this->dispatcher->dispatch( @@ -168,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); - } } From 135edefa6656a4e5a29fb4373f8c895af43d1dcc Mon Sep 17 00:00:00 2001 From: Anton Komarev Date: Sun, 8 Jan 2023 14:16:25 +0300 Subject: [PATCH 4/4] WIP --- src/Console/Commands/Recount.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Console/Commands/Recount.php b/src/Console/Commands/Recount.php index 131ecfa9..bdd0c39a 100644 --- a/src/Console/Commands/Recount.php +++ b/src/Console/Commands/Recount.php @@ -80,12 +80,12 @@ public function handle( $queueConnectionName = $appConfigRepository->get('queue.default'); } - $reactants = $this->collectReactants($reactableType); - $this->warn( "Rebuilding reaction aggregates using `$queueConnectionName` queue connection." ); + $reactants = $this->collectReactants($reactableType); + $this->getOutput()->progressStart($reactants->count()); foreach ($reactants as $reactant) { $this->dispatcher->dispatch(