Refactoring: extract process handling from async job.
This commit is contained in:
parent
be351232d3
commit
d0d33da493
@ -23,21 +23,21 @@ public function runCommand()
|
||||
{
|
||||
$this->isKeepAliveOn = true;
|
||||
|
||||
$this->activity = coolifyProcess($this->command, 'testing-host');
|
||||
$this->activity = remoteProcess($this->command, 'testing-host');
|
||||
}
|
||||
|
||||
public function runSleepingBeauty()
|
||||
{
|
||||
$this->isKeepAliveOn = true;
|
||||
|
||||
$this->activity = coolifyProcess('x=1; while [ $x -le 40 ]; do sleep 0.1 && echo "Welcome $x times" $(( x++ )); done', 'testing-host');
|
||||
$this->activity = remoteProcess('x=1; while [ $x -le 40 ]; do sleep 0.1 && echo "Welcome $x times" $(( x++ )); done', 'testing-host');
|
||||
}
|
||||
|
||||
public function runDummyProjectBuild()
|
||||
{
|
||||
$this->isKeepAliveOn = true;
|
||||
|
||||
$this->activity = coolifyProcess(<<<EOT
|
||||
$this->activity = remoteProcess(<<<EOT
|
||||
cd projects/dummy-project
|
||||
~/.docker/cli-plugins/docker-compose build --no-cache
|
||||
EOT, 'testing-host');
|
||||
|
@ -7,7 +7,6 @@
|
||||
use Illuminate\Contracts\Queue\ShouldBeUnique;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Process\ProcessResult;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Spatie\Activitylog\Contracts\Activity;
|
||||
|
@ -3,7 +3,6 @@
|
||||
namespace App\Services;
|
||||
|
||||
use App\Jobs\ExecuteCoolifyProcess;
|
||||
use Illuminate\Process\ProcessResult;
|
||||
use Spatie\Activitylog\Contracts\Activity;
|
||||
|
||||
class CoolifyProcess
|
||||
@ -36,8 +35,11 @@ public function __invoke(): Activity
|
||||
|
||||
dispatch($job);
|
||||
|
||||
$this->activity->refresh();
|
||||
|
||||
ray($this->activity->id);
|
||||
|
||||
return $this->activity;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -3,21 +3,17 @@
|
||||
use App\Services\CoolifyProcess;
|
||||
use Spatie\Activitylog\Contracts\Activity;
|
||||
|
||||
if (! function_exists('coolifyProcess')) {
|
||||
if (! function_exists('remoteProcess')) {
|
||||
|
||||
/**
|
||||
* Run a Coolify Process, which SSH's into a machine to run the command(s).
|
||||
*
|
||||
*/
|
||||
function coolifyProcess($command, $destination): Activity
|
||||
function remoteProcess($command, $destination): Activity
|
||||
{
|
||||
$process = resolve(CoolifyProcess::class, [
|
||||
return resolve(CoolifyProcess::class, [
|
||||
'destination' => $destination,
|
||||
'command' => $command,
|
||||
]);
|
||||
|
||||
$activityLog = $process();
|
||||
|
||||
return $activityLog;
|
||||
])();
|
||||
}
|
||||
}
|
||||
|
@ -13,21 +13,21 @@
|
||||
$host = 'testing-host';
|
||||
|
||||
// Assert there's no containers start with coolify_test_*
|
||||
$activity = coolifyProcess($areThereCoolifyTestContainers, $host);
|
||||
$activity = remoteProcess($areThereCoolifyTestContainers, $host);
|
||||
ray($activity);
|
||||
$containers = Output::containerList($activity->getExtraProperty('stdout'));
|
||||
expect($containers)->toBeEmpty();
|
||||
|
||||
// start a container nginx -d --name = $containerName
|
||||
$activity = coolifyProcess("docker run -d --name {$containerName} nginx", $host);
|
||||
$activity = remoteProcess("docker run -d --name {$containerName} nginx", $host);
|
||||
expect($activity->getExtraProperty('exitCode'))->toBe(0);
|
||||
|
||||
// docker ps name = $container
|
||||
$activity = coolifyProcess($areThereCoolifyTestContainers, $host);
|
||||
$activity = remoteProcess($areThereCoolifyTestContainers, $host);
|
||||
$containers = Output::containerList($activity->getExtraProperty('stdout'));
|
||||
expect($containers->where('Names', $containerName)->count())->toBe(1);
|
||||
|
||||
// Stop testing containers
|
||||
$activity = coolifyProcess("docker stop $(docker ps --filter='name={$coolifyNamePrefix}*' -q)", $host);
|
||||
$activity = remoteProcess("docker stop $(docker ps --filter='name={$coolifyNamePrefix}*' -q)", $host);
|
||||
expect($activity->getExtraProperty('exitCode'))->toBe(0);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user