Skip to content

Commit b8e95b2

Browse files
committed
feat: force cleanup server
1 parent 8ea50dc commit b8e95b2

File tree

5 files changed

+82
-29
lines changed

5 files changed

+82
-29
lines changed

app/Jobs/DockerCleanupJob.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use Illuminate\Queue\InteractsWithQueue;
1313
use Illuminate\Queue\SerializesModels;
1414
use Illuminate\Support\Facades\Log;
15-
use RuntimeException;
1615

1716
class DockerCleanupJob implements ShouldBeEncrypted, ShouldQueue
1817
{
@@ -27,20 +26,25 @@ public function __construct(public Server $server) {}
2726
public function handle(): void
2827
{
2928
try {
30-
$isInprogress = false;
31-
$this->server->applications()->each(function ($application) use (&$isInprogress) {
32-
if ($application->isDeploymentInprogress()) {
33-
$isInprogress = true;
29+
// $isInprogress = false;
30+
// $this->server->applications()->each(function ($application) use (&$isInprogress) {
31+
// if ($application->isDeploymentInprogress()) {
32+
// $isInprogress = true;
3433

35-
return;
36-
}
37-
});
34+
// return;
35+
// }
36+
// });
3837
// if ($isInprogress) {
3938
// throw new RuntimeException('DockerCleanupJob: ApplicationDeploymentQueue is not empty, skipping...');
4039
// }
4140
if (! $this->server->isFunctional()) {
4241
return;
4342
}
43+
if ($this->server->is_force_cleanup_enabled) {
44+
CleanupDocker::run($this->server);
45+
46+
return;
47+
}
4448
$this->usageBefore = $this->server->getDiskUsage();
4549
ray('Usage before: '.$this->usageBefore);
4650
if ($this->usageBefore >= $this->server->settings->cleanup_after_percentage) {

app/Jobs/ServerStatusJob.php

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function handle()
4444
}
4545
try {
4646
if ($this->server->isFunctional()) {
47-
$this->cleanup(notify: false);
47+
$this->cleanup();
4848
$this->remove_unnecessary_coolify_yaml();
4949
if ($this->server->isSentinelEnabled()) {
5050
$this->server->checkSentinel();
@@ -109,23 +109,24 @@ private function remove_unnecessary_coolify_yaml()
109109
}
110110
}
111111

112-
public function cleanup(bool $notify = false): void
112+
public function cleanup(): void
113113
{
114+
if ($this->server->settings->is_force_cleanup_enabled) {
115+
DockerCleanupJob::dispatch($this->server);
116+
117+
return;
118+
}
114119
$this->disk_usage = $this->server->getDiskUsage();
115120
if ($this->disk_usage >= $this->server->settings->cleanup_after_percentage) {
116-
if ($notify) {
117-
if ($this->server->high_disk_usage_notification_sent) {
118-
ray('high disk usage notification already sent');
119-
120-
return;
121-
} else {
122-
$this->server->high_disk_usage_notification_sent = true;
123-
$this->server->save();
124-
$this->server->team?->notify(new HighDiskUsage($this->server, $this->disk_usage, $this->server->settings->cleanup_after_percentage));
125-
}
121+
DockerCleanupJob::dispatch($this->server);
122+
if ($this->server->high_disk_usage_notification_sent) {
123+
ray('high disk usage notification already sent');
124+
125+
return;
126126
} else {
127-
DockerCleanupJob::dispatchSync($this->server);
128-
$this->cleanup(notify: true);
127+
$this->server->high_disk_usage_notification_sent = true;
128+
$this->server->save();
129+
$this->server->team?->notify(new HighDiskUsage($this->server, $this->disk_usage, $this->server->settings->cleanup_after_percentage));
129130
}
130131
} else {
131132
$this->server->high_disk_usage_notification_sent = false;

app/Livewire/Server/Form.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class Form extends Component
3737
'server.settings.is_swarm_manager' => 'required|boolean',
3838
'server.settings.is_swarm_worker' => 'required|boolean',
3939
'server.settings.is_build_server' => 'required|boolean',
40+
'server.settings.is_force_cleanup_enabled' => 'required|boolean',
4041
'server.settings.concurrent_builds' => 'required|integer|min:1',
4142
'server.settings.dynamic_timeout' => 'required|integer|min:1',
4243
'server.settings.is_metrics_enabled' => 'required|boolean',
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::table('server_settings', function (Blueprint $table) {
15+
$table->boolean('is_force_cleanup_enabled')->default(false)->after('is_sentinel_enabled');
16+
});
17+
}
18+
19+
/**
20+
* Reverse the migrations.
21+
*/
22+
public function down(): void
23+
{
24+
Schema::table('server_settings', function (Blueprint $table) {
25+
$table->dropColumn('is_force_cleanup_enabled');
26+
});
27+
}
28+
};

resources/views/livewire/server/form.blade.php

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,32 @@ class="w-full mt-8 mb-4 font-bold box-without-bg bg-coollabs hover:bg-coollabs-1
136136

137137
@if ($server->isFunctional())
138138
<h3 class="pt-4">Settings</h3>
139-
<div class="flex flex-wrap gap-2 sm:flex-nowrap">
140-
<x-forms.input id="cleanup_after_percentage" label="Disk cleanup threshold (%)" required
141-
helper="The disk cleanup task will run when the disk usage exceeds this threshold." />
142-
<x-forms.input id="server.settings.concurrent_builds" label="Number of concurrent builds" required
143-
helper="You can specify the number of simultaneous build processes/deployments that should run concurrently." />
144-
<x-forms.input id="server.settings.dynamic_timeout" label="Deployment timeout (seconds)" required
145-
helper="You can define the maximum duration for a deployment to run before timing it out." />
139+
<div class="flex flex-col gap-2">
140+
<div class="flex flex-col flex-wrap gap-2 sm:flex-nowrap">
141+
@if ($server->settings->is_force_cleanup_enabled)
142+
<div class="w-64">
143+
<x-forms.checkbox
144+
helper="This will cleanup build caches / unused images / etc every 10 minutes."
145+
instantSave id="server.settings.is_force_cleanup_enabled"
146+
label="Force Cleanup Docker Engine" />
147+
</div>
148+
@else
149+
<x-forms.input id="cleanup_after_percentage" label="Disk cleanup threshold (%)" required
150+
helper="The disk cleanup task will run when the disk usage exceeds this threshold." />
151+
<div class="w-64">
152+
<x-forms.checkbox
153+
helper="This will cleanup build caches / unused images / etc every 10 minutes."
154+
instantSave id="server.settings.is_force_cleanup_enabled"
155+
label="Force Cleanup Docker Engine" />
156+
</div>
157+
@endif
158+
</div>
159+
<div class="flex flex-wrap gap-2 sm:flex-nowrap">
160+
<x-forms.input id="server.settings.concurrent_builds" label="Number of concurrent builds" required
161+
helper="You can specify the number of simultaneous build processes/deployments that should run concurrently." />
162+
<x-forms.input id="server.settings.dynamic_timeout" label="Deployment timeout (seconds)" required
163+
helper="You can define the maximum duration for a deployment to run before timing it out." />
164+
</div>
146165
</div>
147166
<div class="flex items-center gap-2 pt-4 pb-2">
148167
<h3>Sentinel</h3>

0 commit comments

Comments
 (0)