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

@@ -4,6 +4,7 @@ namespace App\Services;
use App\Models\Bot;
use App\Bots\BotContract;
use App\Jobs\RunBot;
use Cron\CronExpression;
use Illuminate\Support\Facades\Log;
@@ -16,14 +17,29 @@ class BotService
foreach ($bots as $bot) {
$cron = new CronExpression($bot->schedule);
if ($cron->isDue()) {
$log = $bot->logs()->create([
'status' => 'pending',
'started_at' => now(),
]);
try {
$instance = app($bot->class, ['config' => $bot->config]);
if ($instance instanceof BotContract) {
$instance->run();
dispatch(RunBot::class, $bot, $log);
$log->update([
'started_at' => now(),
'status' => 'running'
]);
}
} catch (\Throwable $e) {
Log::error("Bot [{$bot->name}] failed: " . $e->getMessage());
$log->update([
'finished_at' => now(),
'status' => 'failed',
'error' => $e->getMessage(),
]);
}
Log::info("Bot [{$bot->name}] executed successfully.");