Fix server status check and add new job
This commit is contained in:
		@@ -4,6 +4,7 @@ namespace App\Http\Livewire\Project\Application;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
use App\Actions\Application\StopApplication;
 | 
					use App\Actions\Application\StopApplication;
 | 
				
			||||||
use App\Jobs\ContainerStatusJob;
 | 
					use App\Jobs\ContainerStatusJob;
 | 
				
			||||||
 | 
					use App\Jobs\ServerStatusJob;
 | 
				
			||||||
use App\Models\Application;
 | 
					use App\Models\Application;
 | 
				
			||||||
use Livewire\Component;
 | 
					use Livewire\Component;
 | 
				
			||||||
use Visus\Cuid2\Cuid2;
 | 
					use Visus\Cuid2\Cuid2;
 | 
				
			||||||
@@ -28,6 +29,8 @@ class Heading extends Component
 | 
				
			|||||||
            $this->application->previews->each(function ($preview) {
 | 
					            $this->application->previews->each(function ($preview) {
 | 
				
			||||||
                $preview->refresh();
 | 
					                $preview->refresh();
 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            dispatch(new ServerStatusJob($this->application->destination->server));
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -42,6 +42,7 @@ class Rollback extends Component
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            $image = $this->application->uuid;
 | 
					            $image = $this->application->uuid;
 | 
				
			||||||
 | 
					            if ($this->application->destination->server->isFunctional()) {
 | 
				
			||||||
                $output = instant_remote_process([
 | 
					                $output = instant_remote_process([
 | 
				
			||||||
                    "docker inspect --format='{{.Config.Image}}' {$this->application->uuid}",
 | 
					                    "docker inspect --format='{{.Config.Image}}' {$this->application->uuid}",
 | 
				
			||||||
                ], $this->application->destination->server, throwError: false);
 | 
					                ], $this->application->destination->server, throwError: false);
 | 
				
			||||||
@@ -64,6 +65,8 @@ class Rollback extends Component
 | 
				
			|||||||
                        'is_current' => $is_current ?? null,
 | 
					                        'is_current' => $is_current ?? null,
 | 
				
			||||||
                    ];
 | 
					                    ];
 | 
				
			||||||
                })->toArray();
 | 
					                })->toArray();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            return [];
 | 
				
			||||||
        } catch (\Throwable $e) {
 | 
					        } catch (\Throwable $e) {
 | 
				
			||||||
            return handleError($e, $this);
 | 
					            return handleError($e, $this);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -37,8 +37,9 @@ class ContainerStatusJob implements ShouldQueue, ShouldBeEncrypted
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    public function handle(): void
 | 
					    public function handle(): void
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        // ray("checking server status for {$this->server->id}");
 | 
					        ray("checking container statuses for {$this->server->id}");
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
 | 
					            $this->server->checkServerRediness();
 | 
				
			||||||
            $containers = instant_remote_process(["docker container ls -q"], $this->server);
 | 
					            $containers = instant_remote_process(["docker container ls -q"], $this->server);
 | 
				
			||||||
            if (!$containers) {
 | 
					            if (!$containers) {
 | 
				
			||||||
                return;
 | 
					                return;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -131,11 +131,11 @@ class Server extends BaseModel
 | 
				
			|||||||
    public function checkServerRediness()
 | 
					    public function checkServerRediness()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $serverUptimeCheckNumber = $this->unreachable_count;
 | 
					        $serverUptimeCheckNumber = $this->unreachable_count;
 | 
				
			||||||
        $serverUptimeCheckNumberMax = 5;
 | 
					        $serverUptimeCheckNumberMax = 3;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $currentTime = now()->timestamp;
 | 
					        $currentTime = now()->timestamp;
 | 
				
			||||||
        $runtime5Minutes = 1 * 60;
 | 
					        $runtime5Minutes = 1 * 60;
 | 
				
			||||||
        // Run for 1 minutes max and check every 5 seconds
 | 
					        // Run for 1 minutes max and check every 5 seconds for 3 times
 | 
				
			||||||
        while ($currentTime + $runtime5Minutes > now()->timestamp) {
 | 
					        while ($currentTime + $runtime5Minutes > now()->timestamp) {
 | 
				
			||||||
            if ($serverUptimeCheckNumber >= $serverUptimeCheckNumberMax) {
 | 
					            if ($serverUptimeCheckNumber >= $serverUptimeCheckNumberMax) {
 | 
				
			||||||
                if ($this->unreachable_notification_sent === false) {
 | 
					                if ($this->unreachable_notification_sent === false) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -52,7 +52,6 @@ class User extends Authenticatable implements SendsEmail
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
    public function createToken(string $name, array $abilities = ['*'], DateTimeInterface $expiresAt = null)
 | 
					    public function createToken(string $name, array $abilities = ['*'], DateTimeInterface $expiresAt = null)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        ray('asd');
 | 
					 | 
				
			||||||
        $plainTextToken = sprintf(
 | 
					        $plainTextToken = sprintf(
 | 
				
			||||||
            '%s%s%s',
 | 
					            '%s%s%s',
 | 
				
			||||||
            config('sanctum.token_prefix', ''),
 | 
					            config('sanctum.token_prefix', ''),
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user