Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
stepanenko3 committed Mar 18, 2024
1 parent 1960687 commit 5ac079a
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/CommandService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

namespace Stepanenko3\NovaCommandRunner;

use Exception;
use Stepanenko3\NovaCommandRunner\Dto\CommandDto;
use Stepanenko3\NovaCommandRunner\Dto\RunDto;
use Stepanenko3\NovaCommandRunner\Jobs\RunCommand;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Str;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\Process\Process;

/**
Expand Down Expand Up @@ -53,7 +55,7 @@ public static function runCommand(CommandDto $command, RunDto $run)
$start = microtime(true);

try {
$buffer = new \Symfony\Component\Console\Output\BufferedOutput();
$buffer = new BufferedOutput();
if ($command->getType() === self::$TYPE_ARTISAN) {
Artisan::call($command->getParsedCommand(), [], $buffer);
} elseif ($command->getType() === self::$TYPE_BASH) {
Expand All @@ -62,7 +64,7 @@ public static function runCommand(CommandDto $command, RunDto $run)
$buffer->writeln($message);
});
} else {
throw new \Exception('Unknown command type: ' . $command->getType());
throw new Exception('Unknown command type: ' . $command->getType());
}

$output = $buffer->fetch();
Expand All @@ -78,7 +80,7 @@ public static function runCommand(CommandDto $command, RunDto $run)

$run->setStatus('success')
->setResult($output);
} catch (\Exception $exception) {
} catch (Exception $exception) {
$run->setResult($exception->getMessage());
$run->setStatus('error');
}
Expand All @@ -89,6 +91,8 @@ public static function runCommand(CommandDto $command, RunDto $run)
}

/**
* @param mixed $command
*
* @return array
*/
public static function parseCommandForQueue($command)
Expand Down Expand Up @@ -156,6 +160,8 @@ public static function getHistory()
}

/**
* @param mixed $history
*
* @return mixed
*/
public static function saveHistory($history)
Expand Down

0 comments on commit 5ac079a

Please sign in to comment.