37 lines
1.2 KiB
PHP
37 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs;
|
|
|
|
use App\Models\ServiceTask;
|
|
use App\Enums\ServiceTaskStatus;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Queue\Queueable;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class CheckSlaDeadlines implements ShouldQueue
|
|
{
|
|
use Queueable;
|
|
|
|
public function handle(): void
|
|
{
|
|
$overdueTasks = ServiceTask::where('status', '!=', ServiceTaskStatus::Completed)
|
|
->where('sla_deadline', '<', now())
|
|
->with(['service', 'integrationRequest.agent'])
|
|
->get();
|
|
|
|
foreach ($overdueTasks as $task) {
|
|
// Log for audit
|
|
Log::warning("SLA Overdue for task ID {$task->id} (Service: {$task->service->name})");
|
|
|
|
// Notify service members
|
|
$serviceRole = $task->service->name;
|
|
$users = \App\Models\User::role($serviceRole)->get();
|
|
\Illuminate\Support\Facades\Notification::send($users, new \App\Notifications\SlaOverdueNotification($task));
|
|
|
|
// Also notify RH
|
|
$rhUsers = \App\Models\User::role('RH')->get();
|
|
\Illuminate\Support\Facades\Notification::send($rhUsers, new \App\Notifications\SlaOverdueNotification($task));
|
|
}
|
|
}
|
|
}
|