mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-05 16:02:34 +00:00
fix consecutive deployment issue (#62)
* fix consecutive deployment issue * fix styles
This commit is contained in:
@ -4,7 +4,6 @@
|
||||
|
||||
use App\Enums\DeploymentStatus;
|
||||
use App\Events\Broadcast;
|
||||
use App\Helpers\SSH;
|
||||
use App\Jobs\Job;
|
||||
use App\Models\Deployment;
|
||||
use App\SSHCommands\System\RunScriptCommand;
|
||||
@ -18,13 +17,11 @@ class Deploy extends Job
|
||||
|
||||
protected string $script;
|
||||
|
||||
protected SSH $ssh;
|
||||
|
||||
public function __construct(Deployment $deployment, string $path, string $script)
|
||||
public function __construct(Deployment $deployment, string $path)
|
||||
{
|
||||
$this->script = $deployment->deploymentScript->content;
|
||||
$this->deployment = $deployment;
|
||||
$this->path = $path;
|
||||
$this->script = $script;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -32,28 +29,31 @@ public function __construct(Deployment $deployment, string $path, string $script
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
$this->ssh = $this->deployment->site->server->ssh();
|
||||
$this->ssh->exec(
|
||||
new RunScriptCommand($this->path, $this->script),
|
||||
'deploy',
|
||||
$this->deployment->site_id
|
||||
);
|
||||
$this->deployment->status = DeploymentStatus::FINISHED;
|
||||
$this->deployment->log_id = $this->ssh->log->id;
|
||||
$this->deployment->save();
|
||||
event(
|
||||
new Broadcast('deploy-site-finished', [
|
||||
'deployment' => $this->deployment,
|
||||
])
|
||||
);
|
||||
$ssh = $this->deployment->site->server->ssh();
|
||||
try {
|
||||
$ssh->exec(
|
||||
new RunScriptCommand($this->path, $this->script),
|
||||
'deploy',
|
||||
$this->deployment->site_id
|
||||
);
|
||||
$this->deployment->status = DeploymentStatus::FINISHED;
|
||||
$this->deployment->log_id = $ssh->log->id;
|
||||
$this->deployment->save();
|
||||
event(
|
||||
new Broadcast('deploy-site-finished', [
|
||||
'deployment' => $this->deployment,
|
||||
])
|
||||
);
|
||||
} catch (Throwable) {
|
||||
$this->deployment->log_id = $ssh->log->id;
|
||||
$this->deployment->save();
|
||||
$this->failed();
|
||||
}
|
||||
}
|
||||
|
||||
public function failed(): void
|
||||
{
|
||||
$this->deployment->status = DeploymentStatus::FAILED;
|
||||
if ($this->ssh->log) {
|
||||
$this->deployment->log_id = $this->ssh->log->id;
|
||||
}
|
||||
$this->deployment->save();
|
||||
event(
|
||||
new Broadcast('deploy-site-failed', [
|
||||
|
Reference in New Issue
Block a user