Files
Scheduler/app/Jobs/RunBot.php
Oskar-Mikael 378355ad5b
All checks were successful
Deploy App / deploy (push) Successful in 11s
Add bot logs
2025-08-31 21:54:18 +02:00

45 lines
1.1 KiB
PHP

<?php
namespace App\Jobs;
use App\Models\Bot;
use App\Models\BotLog;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;
class RunBot implements ShouldQueue
{
use Queueable;
/**
* Create a new job instance.
*/
public function __construct(private Bot $bot, private BotLog $log) {}
/**
* Execute the job.
*/
public function handle(): void
{
$class = new $this->bot->class($this->bot->config ?? []);
try {
$class->run();
// Update the log entry on success
$this->log->update([
'finished_at' => now(),
'status' => 'success',
// 'output' => is_string($result) ? $result : json_encode($result, JSON_PRETTY_PRINT),
]);
} catch (\Throwable $e) {
// Log the error in the bot log
$this->log->update([
'finished_at' => now(),
'status' => 'failed',
'error' => $e->getMessage(),
]);
}
}
}