Add bot logs
All checks were successful
Deploy App / deploy (push) Successful in 11s

This commit is contained in:
2025-08-31 21:54:18 +02:00
parent 77ebc6bce1
commit 378355ad5b
16 changed files with 355 additions and 20 deletions

View File

@@ -3,6 +3,7 @@
namespace App\Jobs;
use App\Models\Bot;
use App\Models\BotLog;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;
@@ -13,9 +14,7 @@ class RunBot implements ShouldQueue
/**
* Create a new job instance.
*/
public function __construct(private Bot $bot)
{
}
public function __construct(private Bot $bot, private BotLog $log) {}
/**
* Execute the job.
@@ -24,6 +23,22 @@ class RunBot implements ShouldQueue
{
$class = new $this->bot->class($this->bot->config ?? []);
$class->run();
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(),
]);
}
}
}