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