This commit is contained in:
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user