2023-10-14 12:22:07 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Jobs;
|
|
|
|
|
|
|
|
use App\Actions\Application\StopApplication;
|
|
|
|
use App\Actions\Database\StopDatabase;
|
2023-12-08 17:32:08 +00:00
|
|
|
use App\Actions\Service\DeleteService;
|
2023-10-14 12:22:07 +00:00
|
|
|
use App\Models\Application;
|
|
|
|
use App\Models\Service;
|
2023-10-24 12:31:28 +00:00
|
|
|
use App\Models\StandaloneMariadb;
|
2023-10-19 11:32:03 +00:00
|
|
|
use App\Models\StandaloneMongodb;
|
2023-10-24 12:31:28 +00:00
|
|
|
use App\Models\StandaloneMysql;
|
2023-10-14 12:22:07 +00:00
|
|
|
use App\Models\StandalonePostgresql;
|
|
|
|
use App\Models\StandaloneRedis;
|
|
|
|
use Illuminate\Bus\Queueable;
|
|
|
|
use Illuminate\Contracts\Queue\ShouldBeEncrypted;
|
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
|
2023-11-06 10:51:20 +00:00
|
|
|
class DeleteResourceJob implements ShouldQueue, ShouldBeEncrypted
|
2023-10-14 12:22:07 +00:00
|
|
|
{
|
|
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
|
2023-10-24 12:31:28 +00:00
|
|
|
public function __construct(public Application|Service|StandalonePostgresql|StandaloneRedis|StandaloneMongodb|StandaloneMysql|StandaloneMariadb $resource)
|
2023-10-14 12:22:07 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public function handle()
|
|
|
|
{
|
|
|
|
try {
|
2024-01-17 14:48:01 +00:00
|
|
|
$this->resource->delete();
|
2023-10-14 12:22:07 +00:00
|
|
|
switch ($this->resource->type()) {
|
|
|
|
case 'application':
|
|
|
|
StopApplication::run($this->resource);
|
|
|
|
break;
|
|
|
|
case 'standalone-postgresql':
|
|
|
|
StopDatabase::run($this->resource);
|
|
|
|
break;
|
|
|
|
case 'standalone-redis':
|
|
|
|
StopDatabase::run($this->resource);
|
|
|
|
break;
|
2023-10-19 11:32:03 +00:00
|
|
|
case 'standalone-mongodb':
|
|
|
|
StopDatabase::run($this->resource);
|
|
|
|
break;
|
2023-10-24 12:31:28 +00:00
|
|
|
case 'standalone-mysql':
|
|
|
|
StopDatabase::run($this->resource);
|
|
|
|
break;
|
|
|
|
case 'standalone-mariadb':
|
|
|
|
StopDatabase::run($this->resource);
|
|
|
|
break;
|
2024-01-30 08:48:51 +00:00
|
|
|
case 'service':
|
|
|
|
DeleteService::dispatch($this->resource);
|
|
|
|
break;
|
2023-12-08 17:32:08 +00:00
|
|
|
}
|
2023-10-14 12:22:07 +00:00
|
|
|
} catch (\Throwable $e) {
|
|
|
|
send_internal_notification('ContainerStoppingJob failed with: ' . $e->getMessage());
|
|
|
|
throw $e;
|
2024-01-30 08:48:51 +00:00
|
|
|
} finally {
|
|
|
|
$this->resource->forceDelete();
|
2023-10-14 12:22:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|