could you add the recount logic to a separate class or job please
vesper8 opened this issue · comments
I have had to clone your entire Recount command just so I could stick
ini_set('max_execution_time', 9999);
ini_set('memory_limit', '2048M');
in the handle
part
I also tried extending it like so:
<?php
namespace App\Console\Commands;
use Illuminate\Queue\QueueManager;
class RecountLaravelLove extends \Cog\Laravel\Love\Console\Commands\Recount
{
protected $name = 'custom:love:recount';
protected $queueManager;
public function __construct(QueueManager $queueManager)
{
$this->queueManager = $queueManager;
parent::__construct();
}
public function handle(): void
{
ini_set('max_execution_time', 9999);
ini_set('memory_limit', '2048M');
parent::handle();
}
}
And this would be a fine solution but you've marked your Recount class as final
so it can't be extended. Could you perhaps remove the final
from it so I can extend it and have it run in sync even if it takes longer? Either that or abstract it so it can be easier to call a Recount from a controller or custom command
Personally, I am a fan of having console commands call jobs and putting all the heavy lifting in the job class and keeping the command class short and sweet
If you have a time - I will be glad to receive a recounting job as PR. I will review it and try to push it further as soon as possible.
There is no need to refactor console command at this moment. Just create a Job class as a first step.
@vesper8 You could try new job introduced in #148 in the master branch:
composer require cybercog/laravel-love:dev-master
RebuildReactionAggregatesJob::dispatch($reactant, $reactionType);
It's using queues, so if you want to call it synchronously you could call it on sync
connection:
RebuildReactionAggregatesJob::dispatch($reactant, $reactionType)
->onConnection('sync');
It will be released as v8.3 on the next week.