2023-03-20 12:04:22 +00:00
|
|
|
<?php
|
|
|
|
|
2023-05-03 05:15:45 +00:00
|
|
|
namespace App\Actions\CoolifyTask;
|
2023-03-20 12:04:22 +00:00
|
|
|
|
2023-05-03 05:15:45 +00:00
|
|
|
use App\Data\CoolifyTaskArgs;
|
2023-05-03 06:24:34 +00:00
|
|
|
use App\Jobs\CoolifyTask;
|
2023-03-21 10:32:38 +00:00
|
|
|
use Spatie\Activitylog\Models\Activity;
|
2023-03-20 12:04:22 +00:00
|
|
|
|
2023-05-03 06:24:34 +00:00
|
|
|
/**
|
|
|
|
* The initial step to run a `CoolifyTask`: a remote SSH process
|
|
|
|
* with monitoring/tracking/trace feature. Such thing is made
|
|
|
|
* possible using an Activity model and some attributes.
|
|
|
|
*/
|
2023-05-03 05:15:45 +00:00
|
|
|
class PrepareCoolifyTask
|
2023-03-20 12:04:22 +00:00
|
|
|
{
|
|
|
|
protected Activity $activity;
|
|
|
|
|
2023-05-03 05:15:45 +00:00
|
|
|
public function __construct(CoolifyTaskArgs $remoteProcessArgs)
|
2023-03-29 10:27:02 +00:00
|
|
|
{
|
|
|
|
if ($remoteProcessArgs->model) {
|
|
|
|
$properties = $remoteProcessArgs->toArray();
|
|
|
|
unset($properties['model']);
|
|
|
|
|
|
|
|
$this->activity = activity()
|
|
|
|
->withProperties($properties)
|
|
|
|
->performedOn($remoteProcessArgs->model)
|
2023-03-30 07:47:04 +00:00
|
|
|
->event($remoteProcessArgs->type)
|
2023-04-07 14:58:45 +00:00
|
|
|
->log("[]");
|
2023-03-29 10:27:02 +00:00
|
|
|
} else {
|
|
|
|
$this->activity = activity()
|
|
|
|
->withProperties($remoteProcessArgs->toArray())
|
2023-03-30 07:47:04 +00:00
|
|
|
->event($remoteProcessArgs->type)
|
2023-04-07 14:58:45 +00:00
|
|
|
->log("[]");
|
2023-03-29 10:27:02 +00:00
|
|
|
}
|
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
|
|
|
{
|
2023-05-03 06:24:34 +00:00
|
|
|
$job = new CoolifyTask($this->activity);
|
2023-03-20 12:04:22 +00:00
|
|
|
dispatch($job);
|
2023-03-21 09:31:16 +00:00
|
|
|
$this->activity->refresh();
|
2023-03-20 12:04:22 +00:00
|
|
|
return $this->activity;
|
|
|
|
}
|
|
|
|
}
|