This commit is contained in:
@@ -19,7 +19,6 @@ class GenericApi implements BotContract
|
||||
|
||||
public function run(): void
|
||||
{
|
||||
try {
|
||||
$this->client = new Client();
|
||||
|
||||
$options = [];
|
||||
@@ -37,9 +36,6 @@ class GenericApi implements BotContract
|
||||
$this->config['url'],
|
||||
$options
|
||||
);
|
||||
} catch (GuzzleException $e) {
|
||||
Log::error("Call to {$this->config['url']} failed" . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static function configSchema(): array
|
||||
|
||||
@@ -14,27 +14,30 @@ class RunBot implements ShouldQueue
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*/
|
||||
public function __construct(private Bot $bot, private BotLog $log) {}
|
||||
public function __construct(private int $bot_id, private int $log_id) {}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
$class = new $this->bot->class($this->bot->config ?? []);
|
||||
$bot = Bot::findOrFail($this->bot_id);
|
||||
$log = BotLog::findOrFail($this->log_id);
|
||||
|
||||
try {
|
||||
$class = new $bot->class($bot->config ?? []);
|
||||
|
||||
$class->run();
|
||||
|
||||
// Update the log entry on success
|
||||
$this->log->update([
|
||||
$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([
|
||||
$log->update([
|
||||
'finished_at' => now(),
|
||||
'status' => 'failed',
|
||||
'error' => $e->getMessage(),
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Livewire;
|
||||
|
||||
use App\Models\BotLog;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Jantinnerezo\LivewireAlert\Facades\LivewireAlert;
|
||||
use Livewire\Component;
|
||||
use Livewire\WithoutUrlPagination;
|
||||
use Livewire\WithPagination;
|
||||
@@ -13,15 +14,18 @@ class BotLogs extends Component
|
||||
use WithPagination;
|
||||
use WithoutUrlPagination;
|
||||
|
||||
// public function mount()
|
||||
// {
|
||||
// $this->getLogs();
|
||||
// }
|
||||
|
||||
// public function getLogs(): void
|
||||
// {
|
||||
// $this->logs = Auth::user()->bots->pluck('logs')->flatten()->sortByDesc('created_at');
|
||||
// }
|
||||
public function showError(int $logId): void
|
||||
{
|
||||
$log = BotLog::find($logId);
|
||||
if ($log) {
|
||||
LivewireAlert::title('Error Details')
|
||||
->html("<pre class='whitespace-pre-wrap break-words'>{$log->error}</pre>")
|
||||
->warning()
|
||||
->timer(null)
|
||||
->withCancelButton('Close')
|
||||
->show();
|
||||
}
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
|
||||
@@ -78,7 +78,7 @@ class BotsList extends Component
|
||||
]);
|
||||
|
||||
// Dispatch the job to run the bot
|
||||
dispatch(new RunBot($bot, $log));
|
||||
dispatch(new RunBot($bot->id, $log->id));
|
||||
|
||||
flash()->success("Bot '{$bot->name}' is being executed.");
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ class ViewBot extends Component
|
||||
]);
|
||||
|
||||
// Dispatch the job to run the bot
|
||||
dispatch(new RunBot($this->bot, $log));
|
||||
dispatch(new RunBot($this->bot->id, $log->id));
|
||||
|
||||
flash()->success("Bot '{$this->bot->name}' is being executed.");
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ class BotService
|
||||
$instance = app($bot->class, ['config' => $bot->config]);
|
||||
|
||||
if ($instance instanceof BotContract) {
|
||||
dispatch(RunBot::class, $bot, $log);
|
||||
dispatch(RunBot::class, $bot->id, $log->id);
|
||||
$log->update([
|
||||
'started_at' => now(),
|
||||
'status' => 'running'
|
||||
|
||||
@@ -16,19 +16,26 @@
|
||||
</td>
|
||||
<td
|
||||
@class([
|
||||
'text-red-400' => $log->status === 'failed',
|
||||
'text-green-400' => $log->status === 'success',
|
||||
'text-yellow-400' => $log->status === 'pending',
|
||||
"text-red-400" => $log->status === "failed",
|
||||
"text-green-400" => $log->status === "success",
|
||||
"text-yellow-400" => $log->status === "pending",
|
||||
]),
|
||||
class="px-4 py-2"
|
||||
@if ($log->status === "failed")
|
||||
wire:click="showError({{ $log->id }})"
|
||||
style="cursor: pointer;"
|
||||
@endif
|
||||
>
|
||||
{{ $log->status }}
|
||||
@if ($log->status === "failed")
|
||||
<i class="fas fa-exclamation-circle ml-1"></i>
|
||||
@endif
|
||||
</td>
|
||||
<td class="px-4 py-2">
|
||||
{{ $log->started_at ?? '' }}
|
||||
{{ $log->started_at ?? "" }}
|
||||
</td>
|
||||
<td class="px-4 py-2">
|
||||
{{ $log->finished_at ?? '' }}
|
||||
{{ $log->finished_at ?? "" }}
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
|
||||
Reference in New Issue
Block a user