Skip to content

Commit

Permalink
fix: make sure important jobs/actions are running on high prio queue
Browse files Browse the repository at this point in the history
  • Loading branch information
andrasbacsai committed Nov 22, 2024
1 parent ef629d5 commit 7dc65df
Show file tree
Hide file tree
Showing 58 changed files with 167 additions and 75 deletions.
2 changes: 2 additions & 0 deletions app/Actions/Application/StopApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class StopApplication
{
use AsAction;

public string $jobQueue = 'high';

public function handle(Application $application, bool $previewDeployments = false, bool $dockerCleanup = true)
{
try {
Expand Down
2 changes: 1 addition & 1 deletion app/Actions/CoolifyTask/PrepareCoolifyTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function __invoke(): Activity
call_event_on_finish: $this->remoteProcessArgs->call_event_on_finish,
call_event_data: $this->remoteProcessArgs->call_event_data,
);
dispatch($job)->onQueue('high');
dispatch($job);
$this->activity->refresh();

return $this->activity;
Expand Down
4 changes: 3 additions & 1 deletion app/Actions/Database/StartDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class StartDatabase
{
use AsAction;

public string $jobQueue = 'high';

public function handle(StandaloneRedis|StandalonePostgresql|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|StandaloneDragonfly|StandaloneClickhouse $database)
{
$server = $database->destination->server;
Expand Down Expand Up @@ -49,7 +51,7 @@ public function handle(StandaloneRedis|StandalonePostgresql|StandaloneMongodb|St
break;
}
if ($database->is_public && $database->public_port) {
StartDatabaseProxy::dispatch($database)->onQueue('high');
StartDatabaseProxy::dispatch($database);
}

return $activity;
Expand Down
2 changes: 2 additions & 0 deletions app/Actions/Database/StartDatabaseProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class StartDatabaseProxy
{
use AsAction;

public string $jobQueue = 'high';

public function handle(StandaloneRedis|StandalonePostgresql|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|StandaloneDragonfly|StandaloneClickhouse|ServiceDatabase $database)
{
$internalPort = null;
Expand Down
2 changes: 2 additions & 0 deletions app/Actions/Database/StopDatabaseProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class StopDatabaseProxy
{
use AsAction;

public string $jobQueue = 'high';

public function handle(StandaloneRedis|StandalonePostgresql|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|ServiceDatabase|StandaloneDragonfly|StandaloneClickhouse $database)
{
$server = data_get($database, 'destination.server');
Expand Down
3 changes: 2 additions & 1 deletion app/Actions/Docker/GetContainersStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use App\Models\ApplicationPreview;
use App\Models\Server;
use App\Models\ServiceDatabase;
use App\Notifications\Container\ContainerRestarted;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Lorisleiva\Actions\Concerns\AsAction;
Expand All @@ -16,6 +15,8 @@ class GetContainersStatus
{
use AsAction;

public string $jobQueue = 'high';

public $applications;

public ?Collection $containers;
Expand Down
2 changes: 2 additions & 0 deletions app/Actions/Server/CleanupDocker.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class CleanupDocker
{
use AsAction;

public string $jobQueue = 'high';

public function handle(Server $server)
{
$settings = instanceSettings();
Expand Down
4 changes: 2 additions & 2 deletions app/Actions/Server/ServerCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ private function checkLogDrainContainer()
if ($foundLogDrainContainer) {
$status = data_get($foundLogDrainContainer, 'State.Status');
if ($status !== 'running') {
StartLogDrain::dispatch($this->server)->onQueue('high');
StartLogDrain::dispatch($this->server);
}
} else {
StartLogDrain::dispatch($this->server)->onQueue('high');
StartLogDrain::dispatch($this->server);
}
}

Expand Down
2 changes: 2 additions & 0 deletions app/Actions/Server/StartLogDrain.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class StartLogDrain
{
use AsAction;

public string $jobQueue = 'high';

public function handle(Server $server)
{
if ($server->settings->is_logdrain_newrelic_enabled) {
Expand Down
2 changes: 1 addition & 1 deletion app/Actions/Server/UpdateCoolify.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function handle($manual_update = false)
if (! $this->server) {
return;
}
CleanupDocker::dispatch($this->server)->onQueue('high');
CleanupDocker::dispatch($this->server);
$this->latestVersion = get_latest_version_of_coolify();
$this->currentVersion = config('version');
if (! $manual_update) {
Expand Down
2 changes: 2 additions & 0 deletions app/Actions/Server/ValidateServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class ValidateServer
{
use AsAction;

public string $jobQueue = 'high';

public ?string $uptime = null;

public ?string $error = null;
Expand Down
2 changes: 2 additions & 0 deletions app/Actions/Service/RestartService.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class RestartService
{
use AsAction;

public string $jobQueue = 'high';

public function handle(Service $service)
{
StopService::run($service);
Expand Down
2 changes: 2 additions & 0 deletions app/Actions/Service/StartService.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class StartService
{
use AsAction;

public string $jobQueue = 'high';

public function handle(Service $service)
{
$service->saveComposeConfigs();
Expand Down
2 changes: 2 additions & 0 deletions app/Actions/Service/StopService.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class StopService
{
use AsAction;

public string $jobQueue = 'high';

public function handle(Service $service, bool $isDeleteOperation = false, bool $dockerCleanup = true)
{
try {
Expand Down
6 changes: 3 additions & 3 deletions app/Console/Commands/ServicesDelete.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private function deleteApplication()
if (! $confirmed) {
break;
}
DeleteResourceJob::dispatch($toDelete)->onQueue('high');
DeleteResourceJob::dispatch($toDelete);
}
}
}
Expand All @@ -122,7 +122,7 @@ private function deleteDatabase()
if (! $confirmed) {
return;
}
DeleteResourceJob::dispatch($toDelete)->onQueue('high');
DeleteResourceJob::dispatch($toDelete);
}
}
}
Expand All @@ -148,7 +148,7 @@ private function deleteService()
if (! $confirmed) {
return;
}
DeleteResourceJob::dispatch($toDelete)->onQueue('high');
DeleteResourceJob::dispatch($toDelete);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions app/Http/Controllers/Api/ApplicationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1224,7 +1224,7 @@ private function create_application(Request $request, $type)
$service->name = "service-$service->uuid";
$service->parse(isNew: true);
if ($instantDeploy) {
StartService::dispatch($service)->onQueue('high');
StartService::dispatch($service);
}

return response()->json(serializeApiResponse([
Expand Down Expand Up @@ -1379,7 +1379,7 @@ public function delete_by_uuid(Request $request)
deleteVolumes: $request->query->get('delete_volumes', true),
dockerCleanup: $request->query->get('docker_cleanup', true),
deleteConnectedNetworks: $request->query->get('delete_connected_networks', true)
)->onQueue('high');
);

return response()->json([
'message' => 'Application deletion request queued.',
Expand Down Expand Up @@ -2523,7 +2523,7 @@ public function action_stop(Request $request)
if (! $application) {
return response()->json(['message' => 'Application not found.'], 404);
}
StopApplication::dispatch($application)->onQueue('high');
StopApplication::dispatch($application);

return response()->json(
[
Expand Down
28 changes: 14 additions & 14 deletions app/Http/Controllers/Api/DatabasesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -497,9 +497,9 @@ public function update_by_uuid(Request $request)
$database->update($request->all());

if ($whatToDoWithDatabaseProxy === 'start') {
StartDatabaseProxy::dispatch($database)->onQueue('high');
StartDatabaseProxy::dispatch($database);
} elseif ($whatToDoWithDatabaseProxy === 'stop') {
StopDatabaseProxy::dispatch($database)->onQueue('high');
StopDatabaseProxy::dispatch($database);
}

return response()->json([
Expand Down Expand Up @@ -1151,7 +1151,7 @@ public function create_database(Request $request, NewDatabaseTypes $type)
}
$database = create_standalone_postgresql($environment->id, $destination->uuid, $request->all());
if ($instantDeploy) {
StartDatabase::dispatch($database)->onQueue('high');
StartDatabase::dispatch($database);
}
$database->refresh();
$payload = [
Expand Down Expand Up @@ -1206,7 +1206,7 @@ public function create_database(Request $request, NewDatabaseTypes $type)
}
$database = create_standalone_mariadb($environment->id, $destination->uuid, $request->all());
if ($instantDeploy) {
StartDatabase::dispatch($database)->onQueue('high');
StartDatabase::dispatch($database);
}

$database->refresh();
Expand Down Expand Up @@ -1264,7 +1264,7 @@ public function create_database(Request $request, NewDatabaseTypes $type)
}
$database = create_standalone_mysql($environment->id, $destination->uuid, $request->all());
if ($instantDeploy) {
StartDatabase::dispatch($database)->onQueue('high');
StartDatabase::dispatch($database);
}

$database->refresh();
Expand Down Expand Up @@ -1320,7 +1320,7 @@ public function create_database(Request $request, NewDatabaseTypes $type)
}
$database = create_standalone_redis($environment->id, $destination->uuid, $request->all());
if ($instantDeploy) {
StartDatabase::dispatch($database)->onQueue('high');
StartDatabase::dispatch($database);
}

$database->refresh();
Expand Down Expand Up @@ -1357,7 +1357,7 @@ public function create_database(Request $request, NewDatabaseTypes $type)
removeUnnecessaryFieldsFromRequest($request);
$database = create_standalone_dragonfly($environment->id, $destination->uuid, $request->all());
if ($instantDeploy) {
StartDatabase::dispatch($database)->onQueue('high');
StartDatabase::dispatch($database);
}

return response()->json(serializeApiResponse([
Expand Down Expand Up @@ -1406,7 +1406,7 @@ public function create_database(Request $request, NewDatabaseTypes $type)
}
$database = create_standalone_keydb($environment->id, $destination->uuid, $request->all());
if ($instantDeploy) {
StartDatabase::dispatch($database)->onQueue('high');
StartDatabase::dispatch($database);
}

$database->refresh();
Expand Down Expand Up @@ -1442,7 +1442,7 @@ public function create_database(Request $request, NewDatabaseTypes $type)
removeUnnecessaryFieldsFromRequest($request);
$database = create_standalone_clickhouse($environment->id, $destination->uuid, $request->all());
if ($instantDeploy) {
StartDatabase::dispatch($database)->onQueue('high');
StartDatabase::dispatch($database);
}

$database->refresh();
Expand Down Expand Up @@ -1500,7 +1500,7 @@ public function create_database(Request $request, NewDatabaseTypes $type)
}
$database = create_standalone_mongodb($environment->id, $destination->uuid, $request->all());
if ($instantDeploy) {
StartDatabase::dispatch($database)->onQueue('high');
StartDatabase::dispatch($database);
}

$database->refresh();
Expand Down Expand Up @@ -1593,7 +1593,7 @@ public function delete_by_uuid(Request $request)
deleteVolumes: $request->query->get('delete_volumes', true),
dockerCleanup: $request->query->get('docker_cleanup', true),
deleteConnectedNetworks: $request->query->get('delete_connected_networks', true)
)->onQueue('high');
);

return response()->json([
'message' => 'Database deletion request queued.',
Expand Down Expand Up @@ -1666,7 +1666,7 @@ public function action_deploy(Request $request)
if (str($database->status)->contains('running')) {
return response()->json(['message' => 'Database is already running.'], 400);
}
StartDatabase::dispatch($database)->onQueue('high');
StartDatabase::dispatch($database);

return response()->json(
[
Expand Down Expand Up @@ -1742,7 +1742,7 @@ public function action_stop(Request $request)
if (str($database->status)->contains('stopped') || str($database->status)->contains('exited')) {
return response()->json(['message' => 'Database is already stopped.'], 400);
}
StopDatabase::dispatch($database)->onQueue('high');
StopDatabase::dispatch($database);

return response()->json(
[
Expand Down Expand Up @@ -1815,7 +1815,7 @@ public function action_restart(Request $request)
if (! $database) {
return response()->json(['message' => 'Database not found.'], 404);
}
RestartDatabase::dispatch($database)->onQueue('high');
RestartDatabase::dispatch($database);

return response()->json(
[
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Api/DeployController.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ public function deploy_resource($resource, bool $force = false): array
break;
default:
// Database resource
StartDatabase::dispatch($resource)->onQueue('high');
StartDatabase::dispatch($resource);
$resource->update([
'started_at' => now(),
]);
Expand Down
6 changes: 3 additions & 3 deletions app/Http/Controllers/Api/ServersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ public function create_server(Request $request)
'is_build_server' => $request->is_build_server,
]);
if ($request->instant_validate) {
ValidateServer::dispatch($server)->onQueue('high');
ValidateServer::dispatch($server);
}

return response()->json([
Expand Down Expand Up @@ -675,7 +675,7 @@ public function update_server(Request $request)
]);
}
if ($request->instant_validate) {
ValidateServer::dispatch($server)->onQueue('high');
ValidateServer::dispatch($server);
}

return response()->json([
Expand Down Expand Up @@ -813,7 +813,7 @@ public function validate_server(Request $request)
if (! $server) {
return response()->json(['message' => 'Server not found.'], 404);
}
ValidateServer::dispatch($server)->onQueue('high');
ValidateServer::dispatch($server);

return response()->json(['message' => 'Validation started.']);
}
Expand Down
Loading

0 comments on commit 7dc65df

Please sign in to comment.