Update crap pane handling

This commit is contained in:
DariusIII
2025-11-03 11:07:41 +01:00
parent 0b6ebf4ea1
commit b8d85136d3
2 changed files with 30 additions and 39 deletions
+14 -12
View File
@@ -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;
}
}
+16 -27
View File
@@ -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];
}
/**