feat: rolling update
This commit is contained in:
52
app/Jobs/DatabaseContainerStatusJob.php
Normal file
52
app/Jobs/DatabaseContainerStatusJob.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Models\ApplicationPreview;
|
||||
use App\Models\StandalonePostgresql;
|
||||
use App\Notifications\Application\StatusChanged;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldBeUnique;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class DatabaseContainerStatusJob implements ShouldQueue, ShouldBeUnique
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
public string $containerName;
|
||||
|
||||
public function __construct(
|
||||
public StandalonePostgresql $database,
|
||||
) {
|
||||
$this->containerName = $database->uuid;
|
||||
}
|
||||
|
||||
public function uniqueId(): string
|
||||
{
|
||||
return $this->containerName;
|
||||
}
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
try {
|
||||
$status = getContainerStatus(
|
||||
server: $this->database->destination->server,
|
||||
container_id: $this->containerName,
|
||||
throwError: false
|
||||
);
|
||||
|
||||
if ($this->database->status === 'running' && $status !== 'running') {
|
||||
$this->database->environment->project->team->notify(new StatusChanged($this->database));
|
||||
}
|
||||
if ($this->database->status !== $status) {
|
||||
$this->database->status = $status;
|
||||
$this->database->save();
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
ray($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user