2026-01-26 21:08:59 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2026-01-27 16:30:46 +00:00
|
|
|
namespace Core\Tenant\Jobs;
|
2026-01-26 21:08:59 +00:00
|
|
|
|
2026-01-27 16:30:46 +00:00
|
|
|
use Core\Tenant\Models\User;
|
|
|
|
|
use Core\Tenant\Services\UserStatsService;
|
2026-01-26 21:08:59 +00:00
|
|
|
use Illuminate\Bus\Queueable;
|
|
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
|
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
|
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
|
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
|
|
|
|
|
|
class ComputeUserStats implements ShouldQueue
|
|
|
|
|
{
|
|
|
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
|
|
|
|
|
|
public int $tries = 3;
|
|
|
|
|
|
|
|
|
|
public int $backoff = 30;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a new job instance.
|
|
|
|
|
*/
|
|
|
|
|
public function __construct(
|
|
|
|
|
public int $userId
|
|
|
|
|
) {}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Execute the job.
|
|
|
|
|
*/
|
|
|
|
|
public function handle(UserStatsService $statsService): void
|
|
|
|
|
{
|
|
|
|
|
$user = User::find($this->userId);
|
|
|
|
|
|
|
|
|
|
if (! $user) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$statsService->computeStats($user);
|
|
|
|
|
}
|
|
|
|
|
}
|