lasthourcloud/app/Http/Livewire/RunCommand.php

59 lines
1.5 KiB
PHP
Raw Normal View History

2023-03-20 12:04:22 +00:00
<?php
namespace App\Http\Livewire;
2023-05-03 06:24:34 +00:00
use App\Enums\ActivityTypes;
use App\Models\Server;
2023-03-20 12:04:22 +00:00
use Livewire\Component;
class RunCommand extends Component
{
public $activity;
public $isKeepAliveOn = false;
public $manualKeepAlive = false;
public $command = 'ls';
2023-03-20 12:04:22 +00:00
2023-03-28 13:47:37 +00:00
public $server;
2023-03-24 14:48:57 +00:00
public $servers = [];
protected $rules = [
'server' => 'required',
];
public function mount()
{
$this->servers = Server::all();
$this->server = $this->servers[0]->uuid;
}
2023-03-20 12:04:22 +00:00
public function runCommand()
{
$this->isKeepAliveOn = true;
2023-05-03 06:25:50 +00:00
$this->activity = remoteProcess([$this->command], Server::where('uuid', $this->server)->first(), ActivityTypes::INLINE->value);
2023-03-20 12:04:22 +00:00
}
public function runSleepingBeauty()
{
$this->isKeepAliveOn = true;
2023-05-03 06:25:50 +00:00
$this->activity = remoteProcess(['x=1; while [ $x -le 40 ]; do sleep 0.1 && echo "Welcome $x times" $(( x++ )); done'], Server::where('uuid', $this->server)->first(), ActivityTypes::INLINE->value);
}
public function runDummyProjectBuild()
{
$this->isKeepAliveOn = true;
2023-05-03 06:25:50 +00:00
$this->activity = remoteProcess([' cd projects/dummy-project', 'docker-compose build --no-cache'], Server::where('uuid', $this->server)->first(), ActivityTypes::INLINE->value);
}
2023-03-20 12:04:22 +00:00
public function polling()
{
$this->activity?->refresh();
if (data_get($this->activity, 'properties.exitCode') !== null) {
2023-03-20 12:04:22 +00:00
$this->isKeepAliveOn = false;
}
}
}