fix: notifications

feat: add app stopped notification
This commit is contained in:
Andras Bacsai
2023-07-26 14:46:28 +02:00
parent 98d057a2ac
commit 802ef03013
7 changed files with 146 additions and 5 deletions

View File

@@ -4,6 +4,7 @@ namespace App\Jobs;
use App\Models\Application;
use App\Models\ApplicationPreview;
use App\Notifications\Notifications\Application\ApplicationStoppedNotification;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
@@ -32,8 +33,14 @@ class ApplicationContainerStatusJob implements ShouldQueue, ShouldBeUnique
}
public function handle(): void
{
ray('checking status of ' . $this->container_name);
try {
$status = get_container_status(server: $this->application->destination->server, container_id: $this->container_name, throwError: false);
ray($this->application->status, $status);
if ($this->application->status === 'running' && $status !== 'running') {
$this->application->environment->project->team->notify(new ApplicationStoppedNotification($this->application));
}
if ($this->pull_request_id) {
$preview = ApplicationPreview::findPreviewByApplicationAndPullId($this->application->id, $this->pull_request_id);
$preview->status = $status;

View File

@@ -12,6 +12,8 @@ use App\Models\GitlabApp;
use App\Models\Server;
use App\Models\StandaloneDocker;
use App\Models\SwarmDocker;
use App\Notifications\Notifications\Application\DeployedSuccessfullyNotification;
use App\Notifications\Notifications\Application\DeployedWithErrorNotification;
use App\Traits\ExecuteRemoteCommand;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
@@ -221,6 +223,12 @@ class ApplicationDeploymentJob implements ShouldQueue
]);
}
queue_next_deployment($this->application);
if ($status === ApplicationDeploymentStatus::FINISHED->value) {
$this->application->environment->project->team->notify(new DeployedSuccessfullyNotification($this->application, $this->deployment_uuid, $this->preview));
}
if ($status === ApplicationDeploymentStatus::FAILED->value) {
$this->application->environment->project->team->notify(new DeployedWithErrorNotification($this->application, $this->deployment_uuid, $this->preview));
}
}
private function start_by_compose_file()
{

View File

@@ -0,0 +1,35 @@
<?php
namespace App\Jobs;
use App\Models\Application;
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 InstanceApplicationsStatusJob implements ShouldQueue, ShouldBeUnique
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public $applications;
public function __construct()
{
$this->applications = Application::all();
}
public function handle(): void
{
try {
foreach ($this->applications as $application) {
dispatch(new ApplicationContainerStatusJob(
application: $application,
container_name: generate_container_name($application->uuid),
));
}
} catch (\Exception $e) {
ray($e->getMessage());
}
}
}