@@ -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
0 commit comments