2023-03-20 12:04:22 +00:00
|
|
|
<?php
|
|
|
|
|
2023-03-21 09:56:49 +00:00
|
|
|
namespace App\Actions\RemoteProcess;
|
2023-03-20 12:04:22 +00:00
|
|
|
|
2023-03-21 09:56:49 +00:00
|
|
|
use App\Enums\ActivityTypes;
|
2023-03-21 09:32:16 +00:00
|
|
|
use App\Enums\ProcessStatus;
|
2023-03-20 12:04:22 +00:00
|
|
|
use App\Jobs\ExecuteCoolifyProcess;
|
|
|
|
use Spatie\Activitylog\Contracts\Activity;
|
|
|
|
|
2023-03-21 09:56:49 +00:00
|
|
|
class DispatchRemoteProcess
|
2023-03-20 12:04:22 +00:00
|
|
|
{
|
|
|
|
protected Activity $activity;
|
|
|
|
|
|
|
|
// TODO Left 'root' as default user instead of 'coolify' because
|
|
|
|
// there's a task at TODO.md to run docker without sudo
|
|
|
|
public function __construct(
|
|
|
|
protected string $destination,
|
|
|
|
protected string $command,
|
|
|
|
protected ?int $port = 22,
|
|
|
|
protected ?string $user = 'root',
|
|
|
|
){
|
|
|
|
$this->activity = activity()
|
2023-03-20 14:04:35 +00:00
|
|
|
->withProperties([
|
2023-03-21 09:56:49 +00:00
|
|
|
'type' => ActivityTypes::COOLIFY_PROCESS,
|
|
|
|
'status' => ProcessStatus::HOLDING,
|
2023-03-20 14:04:35 +00:00
|
|
|
'user' => $this->user,
|
|
|
|
'destination' => $this->destination,
|
|
|
|
'port' => $this->port,
|
|
|
|
'command' => $this->command,
|
|
|
|
])
|
2023-03-21 09:08:36 +00:00
|
|
|
->log("Awaiting command to start...\n\n");
|
2023-03-20 12:04:22 +00:00
|
|
|
}
|
|
|
|
|
2023-03-21 09:08:36 +00:00
|
|
|
public function __invoke(): Activity
|
2023-03-20 12:04:22 +00:00
|
|
|
{
|
|
|
|
$job = new ExecuteCoolifyProcess($this->activity);
|
|
|
|
|
|
|
|
dispatch($job);
|
|
|
|
|
2023-03-21 09:31:16 +00:00
|
|
|
$this->activity->refresh();
|
|
|
|
|
2023-03-20 12:04:22 +00:00
|
|
|
return $this->activity;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|