Refactoring: extract process handling from async job.

This commit is contained in:
Joao Patricio
2023-03-21 09:56:49 +00:00
parent 83a7ef21f3
commit cf121062a1
6 changed files with 34 additions and 14 deletions

View File

@@ -1,46 +0,0 @@
<?php
namespace App\Services;
use App\Enums\ProcessStatus;
use App\Jobs\ExecuteCoolifyProcess;
use Spatie\Activitylog\Contracts\Activity;
class CoolifyProcess
{
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()
->withProperties([
'type' => 'COOLIFY_PROCESS',
'user' => $this->user,
'destination' => $this->destination,
'port' => $this->port,
'command' => $this->command,
'status' => ProcessStatus::HOLDING,
])
->log("Awaiting command to start...\n\n");
}
public function __invoke(): Activity
{
$job = new ExecuteCoolifyProcess($this->activity);
dispatch($job);
$this->activity->refresh();
ray($this->activity->id);
return $this->activity;
}
}