fix: cleanup scheduled tasks
This commit is contained in:
parent
8f21ea9367
commit
1f18542960
5 changed files with 21 additions and 3 deletions
|
|
@ -45,6 +45,9 @@ public function handle(Service $service)
|
||||||
foreach ($service->databases()->get() as $database) {
|
foreach ($service->databases()->get() as $database) {
|
||||||
$database->forceDelete();
|
$database->forceDelete();
|
||||||
}
|
}
|
||||||
|
foreach ($service->scheduled_tasks as $task) {
|
||||||
|
$task->delete();
|
||||||
|
}
|
||||||
$service->tags()->detach();
|
$service->tags()->detach();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
namespace App\Console\Commands;
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
use App\Models\Application;
|
use App\Models\Application;
|
||||||
|
use App\Models\ScheduledTask;
|
||||||
use App\Models\Service;
|
use App\Models\Service;
|
||||||
use App\Models\ServiceApplication;
|
use App\Models\ServiceApplication;
|
||||||
use App\Models\ServiceDatabase;
|
use App\Models\ServiceDatabase;
|
||||||
|
|
@ -108,6 +109,17 @@ private function cleanup_stucked_resources()
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
echo "Error in cleaning stuck serviceapp: {$e->getMessage()}\n";
|
echo "Error in cleaning stuck serviceapp: {$e->getMessage()}\n";
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
$scheduled_tasks = ScheduledTask::all();
|
||||||
|
foreach ($scheduled_tasks as $scheduled_task) {
|
||||||
|
if (!$scheduled_task->service && !$scheduled_task->application) {
|
||||||
|
echo "Deleting stuck scheduledtask: {$scheduled_task->name}\n";
|
||||||
|
$scheduled_task->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
echo "Error in cleaning stuck scheduledtasks: {$e->getMessage()}\n";
|
||||||
|
}
|
||||||
|
|
||||||
// Cleanup any resources that are not attached to any environment or destination or server
|
// Cleanup any resources that are not attached to any environment or destination or server
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -120,8 +120,8 @@ private function check_scheduled_tasks($schedule)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
foreach ($scheduled_tasks as $scheduled_task) {
|
foreach ($scheduled_tasks as $scheduled_task) {
|
||||||
$service = $scheduled_task->service()->first();
|
$service = $scheduled_task->service;
|
||||||
$application = $scheduled_task->application()->first();
|
$application = $scheduled_task->application;
|
||||||
|
|
||||||
if (!$application && !$service) {
|
if (!$application && !$service) {
|
||||||
ray('application/service attached to scheduled task does not exist');
|
ray('application/service attached to scheduled task does not exist');
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,9 @@ protected static function booted()
|
||||||
$application->persistentStorages()->delete();
|
$application->persistentStorages()->delete();
|
||||||
$application->environment_variables()->delete();
|
$application->environment_variables()->delete();
|
||||||
$application->environment_variables_preview()->delete();
|
$application->environment_variables_preview()->delete();
|
||||||
|
foreach ($application->scheduled_tasks as $task) {
|
||||||
|
$task->delete();
|
||||||
|
}
|
||||||
$application->tags()->detach();
|
$application->tags()->detach();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<div class="pt-4">
|
<div class="pt-4">
|
||||||
<h3 class="py-4">Recent executions</h3>
|
<h3 class="py-4">Recent executions <span class="text-xs text-neutral-500">(click to check output)</span></h3>
|
||||||
<livewire:project.shared.scheduled-task.executions key="{{ $task->id }}" selectedKey="" :executions="$task->executions->take(-20)" />
|
<livewire:project.shared.scheduled-task.executions key="{{ $task->id }}" selectedKey="" :executions="$task->executions->take(-20)" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue