lasthourcloud/app/Actions/CoolifyTask/PrepareCoolifyTask.php

48 lines
1.5 KiB
PHP
Raw Normal View History

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;
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-06-07 13:39:08 +00:00
protected CoolifyTaskArgs $remoteProcessArgs;
2023-05-03 05:15:45 +00:00
public function __construct(CoolifyTaskArgs $remoteProcessArgs)
{
2023-06-07 13:39:08 +00:00
$this->remoteProcessArgs = $remoteProcessArgs;
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("[]");
} 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-20 12:04:22 +00:00
}
public function __invoke(): Activity
2023-03-20 12:04:22 +00:00
{
$job = new CoolifyTask($this->activity, ignore_errors: $this->remoteProcessArgs->ignore_errors, call_event_on_finish: $this->remoteProcessArgs->call_event_on_finish, call_event_data: $this->remoteProcessArgs->call_event_data);
2023-03-20 12:04:22 +00:00
dispatch($job);
$this->activity->refresh();
2023-03-20 12:04:22 +00:00
return $this->activity;
}
}