From b8d85136d39df290bcb2f29a7b87ce477b1ceda6 Mon Sep 17 00:00:00 2001 From: DariusIII Date: Mon, 3 Nov 2025 11:07:41 +0100 Subject: [PATCH] Update crap pane handling --- Blacklight/TmuxRun.php | 26 +++++++++-------- app/Services/Tmux/TmuxTaskRunner.php | 43 +++++++++++----------------- 2 files changed, 30 insertions(+), 39 deletions(-) diff --git a/Blacklight/TmuxRun.php b/Blacklight/TmuxRun.php index f0f9e63fc..b3b84745e 100755 --- a/Blacklight/TmuxRun.php +++ b/Blacklight/TmuxRun.php @@ -409,23 +409,25 @@ class TmuxRun extends Tmux // Check to see if the pane is dead, if so respawn it. if (shell_exec("tmux list-panes -t{$runVar['constants']['tmux_session']}:1 | grep ^1 | grep -c dead") == 1) { - // Run remove crap releases. + // Build command to run all enabled crap removal options sequentially + $commands = []; + foreach ($runVar['modsettings']['fix_crap'] as $crapType) { + $commands[] = "echo \"\nRunning removeCrapReleases for {$crapType}\"; \ + {$runVar['commands']['_phpn']} {$runVar['paths']['misc']}testing/Releases/removeCrapReleases.php true \ + {$runVar['modsettings']['fc']['time']} {$crapType} $log"; + } + + // Join all commands with semicolons and add final timestamp and sleep + $allCommands = implode('; ', $commands); + + // Run all crap removal options in sequence, then refresh pane when complete shell_exec( "tmux respawnp -t{$runVar['constants']['tmux_session']}:1.1 ' \ - echo \"\nRunning removeCrapReleases for {$runVar['modsettings']['fix_crap'][$runVar['modsettings']['fc']['num']]}\"; \ - {$runVar['commands']['_phpn']} {$runVar['paths']['misc']}testing/Releases/removeCrapReleases.php true \ - {$runVar['modsettings']['fc']['time']} {$runVar['modsettings']['fix_crap'][$runVar['modsettings']['fc']['num']]} $log; \ + {$allCommands}; \ date +\"{$this->_dateFormat}\"; {$runVar['commands']['_sleep']} {$runVar['settings']['crap_timer']}' 2>&1 1> /dev/null" ); - // Increment so we know which type to run next. - $runVar['modsettings']['fc']['num']++; - } - - // If we reached the end, reset the type. - if ((int) $runVar['modsettings']['fc']['num'] === (int) $runVar['modsettings']['fc']['max']) { - $runVar['modsettings']['fc']['num'] = 0; - // And say we are not on the first run, so we run 2 hours the next times. + // Mark that we're not on the first run anymore, so we run 4 hours the next times. $runVar['modsettings']['fc']['firstrun'] = false; } } diff --git a/app/Services/Tmux/TmuxTaskRunner.php b/app/Services/Tmux/TmuxTaskRunner.php index 98f1dff38..f91758b97 100644 --- a/app/Services/Tmux/TmuxTaskRunner.php +++ b/app/Services/Tmux/TmuxTaskRunner.php @@ -403,7 +403,7 @@ class TmuxTaskRunner return $this->paneManager->respawnPane($pane, $command); } - // Handle 'Custom' mode - cycle through selected types + // Handle 'Custom' mode - run all selected types sequentially if ($option === 'Custom') { $selectedTypes = $runVar['settings']['fix_crap'] ?? ''; @@ -418,43 +418,32 @@ class TmuxTaskRunner return $this->disablePane($pane, 'Remove Crap', 'no crap types selected'); } - // Get the next type to process + // Get state to determine if this is first run $stateFile = storage_path('tmux/removecrap_state.json'); $state = $this->loadCrapState($stateFile); - - // Determine current type index - $currentIndex = $state['current_index'] ?? 0; $isFirstRun = $state['first_run'] ?? true; - // Validate index - if ($currentIndex >= count($types)) { - $currentIndex = 0; - $isFirstRun = false; - } - - $currentType = $types[$currentIndex]; - // Determine time limit: full on first run, 4 hours otherwise $time = $isFirstRun ? 'full' : '4'; - // Build and run command - $command = "nice -n{$niceness} php {$artisan} releases:remove-crap --type={$currentType} --time={$time} --delete"; - $command = $this->buildCommand($command, ['log_pane' => 'removecrap', 'sleep' => $sleep]); - - // Update state for next run - $nextIndex = $currentIndex + 1; - if ($nextIndex >= count($types)) { - $nextIndex = 0; - $isFirstRun = false; + // Build commands for all enabled types to run sequentially + $log = $this->getLogFile('removecrap'); + $commands = []; + foreach ($types as $type) { + $commands[] = "echo \"\\nRunning removeCrapReleases for {$type}\"; nice -n{$niceness} php {$artisan} releases:remove-crap --type={$type} --time={$time} --delete 2>&1 | tee -a {$log}"; } + // Join all commands with semicolons and add final timestamp and sleep + $allCommands = implode('; ', $commands); + $fullCommand = "{$allCommands}; date +'%Y-%m-%d %T'; sleep {$sleep}"; + + // Mark that we're not on the first run anymore for next cycle $this->saveCrapState($stateFile, [ - 'current_index' => $nextIndex, - 'first_run' => $isFirstRun, + 'first_run' => false, 'types' => $types, ]); - return $this->paneManager->respawnPane($pane, $command); + return $this->paneManager->respawnPane($pane, $fullCommand); } // Default fallback - disabled @@ -467,13 +456,13 @@ class TmuxTaskRunner protected function loadCrapState(string $file): array { if (! file_exists($file)) { - return ['current_index' => 0, 'first_run' => true]; + return ['first_run' => true]; } $content = file_get_contents($file); $state = json_decode($content, true); - return $state ?: ['current_index' => 0, 'first_run' => true]; + return $state ?: ['first_run' => true]; } /**