44 lines
1.1 KiB
PHP
44 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs;
|
|
|
|
use App\Contracts\AiService;
|
|
use App\Models\User;
|
|
use App\Services\ProgressTrackingService;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Queue\Queueable;
|
|
use Throwable;
|
|
|
|
class AnalyzeStudentPerformance implements ShouldQueue
|
|
{
|
|
use Queueable;
|
|
|
|
public int $tries = 3;
|
|
|
|
public function __construct(public int $studentId) {}
|
|
|
|
public function handle(ProgressTrackingService $tracking, AiService $ai): void
|
|
{
|
|
/** @var User|null $student */
|
|
$student = User::query()->find($this->studentId);
|
|
|
|
if ($student === null) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
$payload = $ai->analyzeStudentPerformance($tracking->buildPerformanceSnapshot($student));
|
|
} catch (Throwable $exception) {
|
|
report($exception);
|
|
|
|
return;
|
|
}
|
|
|
|
$student->aiReports()->create([
|
|
'type' => 'weakness_analysis',
|
|
'payload' => $payload,
|
|
'summary' => is_string($payload['summary'] ?? null) ? $payload['summary'] : null,
|
|
]);
|
|
}
|
|
}
|