This commit is contained in:
29
app/Jobs/RunBot.php
Normal file
29
app/Jobs/RunBot.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Models\Bot;
|
||||
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)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
$class = new $this->bot->class($this->bot->config ?? []);
|
||||
|
||||
$class->run();
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Livewire;
|
||||
|
||||
use App\Jobs\RunBot;
|
||||
use App\Models\Bot;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Jantinnerezo\LivewireAlert\Facades\LivewireAlert;
|
||||
@@ -62,9 +63,7 @@ class BotsList extends Component
|
||||
public function confirmRunBot(Bot $bot): void
|
||||
{
|
||||
// Dispatch the job to run the bot
|
||||
$class = new $bot->class($bot->config ?? []);
|
||||
|
||||
$class->run();
|
||||
dispatch(new RunBot($bot));
|
||||
|
||||
flash()->success("Bot '{$bot->name}' is being executed.");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user