fox/app/Jobs/FoxProactiveJob.php

44 lines
1.0 KiB
PHP

<?php
namespace App\Jobs;
use App\Services\FoxAgent;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
class FoxProactiveJob implements ShouldQueue
{
use Dispatchable;
use InteractsWithQueue;
use Queueable;
use SerializesModels;
public int $timeout = 90;
public function handle(FoxAgent $agent): void
{
try {
$decision = $agent->shouldISpeak();
} catch (\Throwable $e) {
Log::error('FoxProactiveJob: Entscheidung fehlgeschlagen', ['e' => $e->getMessage()]);
return;
}
if (! ($decision['shouldSpeak'] ?? false)) {
return;
}
$message = trim((string) ($decision['message'] ?? ''));
if ($message === '') {
return;
}
$agent->speakProactively($message, (int) ($decision['priority'] ?? 5));
}
}