Skip to content

Commit 7065ee1

Browse files
authored
Merge pull request #34 from open-runtimes/fix-temp-deletion-maintenance
2 parents 4abc3aa + da8b999 commit 7065ee1

File tree

3 files changed

+42
-19
lines changed

3 files changed

+42
-19
lines changed

app/http.php

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -563,12 +563,12 @@ function removeAllRuntimes(Table $activeRuntimes, Pool $orchestrationPool): void
563563
throw new Exception($th->getMessage() . $output, 500);
564564
}
565565

566+
// Container cleanup
566567
if ($remove) {
567568
\sleep(2); // Allow time to read logs
568-
}
569569

570-
// Container cleanup
571-
if ($remove) {
570+
$localDevice->deletePath($tmpFolder);
571+
572572
// Silently try to kill container
573573
try {
574574
$orchestration->remove($containerId, true);
@@ -1164,7 +1164,7 @@ function (string $runtimeId, ?string $payload, string $path, string $method, arr
11641164
$interval = (int) App::getEnv('OPR_EXECUTOR_MAINTENANCE_INTERVAL', '3600'); // In seconds
11651165
Timer::tick($interval * 1000, function () use ($orchestrationPool, $activeRuntimes) {
11661166
Console::info("Running maintenance task ...");
1167-
// TODO: Cleanup /tmp folders when they are not used anymore
1167+
// Stop idling runtimes
11681168
foreach ($activeRuntimes as $activeRuntimeId => $runtime) {
11691169
$inactiveThreshold = \time() - \intval(App::getEnv('OPR_EXECUTOR_INACTIVE_TRESHOLD', '60'));
11701170
if ($runtime['updated'] < $inactiveThreshold) {
@@ -1183,6 +1183,28 @@ function (string $runtimeId, ?string $payload, string $path, string $method, arr
11831183
});
11841184
}
11851185
}
1186+
// Clear leftover build folders
1187+
$localDevice = new Local();
1188+
$tmpPath = DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR;
1189+
$entries = $localDevice->getFiles($tmpPath);
1190+
$prefix = $tmpPath . System::getHostname() . '-';
1191+
foreach ($entries as $entry) {
1192+
if (\str_starts_with($entry, $prefix)) {
1193+
$isActive = false;
1194+
1195+
foreach ($activeRuntimes as $activeRuntimeId => $runtime) {
1196+
if (\str_ends_with($entry, $activeRuntimeId)) {
1197+
$isActive = true;
1198+
break;
1199+
}
1200+
}
1201+
1202+
if (!$isActive) {
1203+
$localDevice->deletePath($entry);
1204+
}
1205+
}
1206+
}
1207+
11861208
Console::success("Maintanance task finished.");
11871209
});
11881210

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"utopia-php/pools": "0.4.*",
3030
"utopia-php/logger": "0.3.*",
3131
"utopia-php/cli": "0.16.*",
32-
"utopia-php/storage": "0.15.*",
32+
"utopia-php/storage": "0.17.*",
3333
"utopia-php/dsn": "0.1.*",
3434
"utopia-php/registry": "0.5.*",
3535
"utopia-php/preloader": "0.2.*",

composer.lock

Lines changed: 15 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)