updates
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
<?php
|
||||
|
||||
use App\Jobs\ApplicationDeploymentJob;
|
||||
use App\Models\Application;
|
||||
use App\Models\ApplicationDeploymentQueue;
|
||||
|
||||
function queue_application_deployment(int $application_id, string $deployment_uuid, int|null $pull_request_id = 0, string $commit = 'HEAD', bool $force_rebuild = false, bool $is_webhook = false)
|
||||
{
|
||||
ray('Queuing deployment: ' . $deployment_uuid . ' of applicationID: ' . $application_id . ' pull request: ' . $pull_request_id . ' with commit: ' . $commit . ' and is it forced: ' . $force_rebuild);
|
||||
$deployment = ApplicationDeploymentQueue::create([
|
||||
'application_id' => $application_id,
|
||||
'deployment_uuid' => $deployment_uuid,
|
||||
@@ -16,8 +16,7 @@ function queue_application_deployment(int $application_id, string $deployment_uu
|
||||
]);
|
||||
$queued_deployments = ApplicationDeploymentQueue::where('application_id', $application_id)->where('status', 'queued')->get()->sortByDesc('created_at');
|
||||
$running_deployments = ApplicationDeploymentQueue::where('application_id', $application_id)->where('status', 'in_progress')->get()->sortByDesc('created_at');
|
||||
ray('Queued deployments: ' . $queued_deployments->count());
|
||||
ray('Running deployments: ' . $running_deployments->count());
|
||||
ray('Q:' . $queued_deployments->count() . 'R:' . $running_deployments->count() . '|Queuing deployment: ' . $deployment_uuid . ' of applicationID: ' . $application_id . ' pull request: ' . $pull_request_id . ' with commit: ' . $commit . ' and is it forced: ' . $force_rebuild);
|
||||
if ($queued_deployments->count() > 1) {
|
||||
$queued_deployments = $queued_deployments->skip(1);
|
||||
$queued_deployments->each(function ($queued_deployment, $key) {
|
||||
@@ -37,3 +36,16 @@ function queue_application_deployment(int $application_id, string $deployment_uu
|
||||
pull_request_id: $pull_request_id,
|
||||
));
|
||||
}
|
||||
|
||||
function queue_next_deployment(Application $application)
|
||||
{
|
||||
$next_found = ApplicationDeploymentQueue::where('application_id', $application->id)->where('status', 'queued')->first();
|
||||
if ($next_found) {
|
||||
dispatch(new ApplicationDeploymentJob(
|
||||
application_deployment_queue_id: $next_found->id,
|
||||
application_id: $next_found->application_id,
|
||||
deployment_uuid: $next_found->deployment_uuid,
|
||||
force_rebuild: $next_found->force_rebuild,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ use App\Models\Server;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Process;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Sleep;
|
||||
use Spatie\Activitylog\Models\Activity;
|
||||
|
||||
/**
|
||||
@@ -76,7 +77,7 @@ function generate_ssh_command(string $private_key_location, string $server_ip, s
|
||||
return $ssh_command;
|
||||
}
|
||||
|
||||
function instant_remote_process(array $command, Server $server, $throwError = true)
|
||||
function instant_remote_process(array $command, Server $server, $throwError = true, $repeat = 1)
|
||||
{
|
||||
$command_string = implode("\n", $command);
|
||||
$private_key_location = save_private_key_for_server($server);
|
||||
@@ -85,6 +86,11 @@ function instant_remote_process(array $command, Server $server, $throwError = tr
|
||||
$output = trim($process->output());
|
||||
$exitCode = $process->exitCode();
|
||||
if ($exitCode !== 0) {
|
||||
if ($repeat > 1) {
|
||||
Sleep::for(200)->milliseconds();
|
||||
ray('executing again');
|
||||
return instant_remote_process($command, $server, $throwError, $repeat - 1);
|
||||
}
|
||||
ray($process->errorOutput());
|
||||
if (!$throwError) {
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user