mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-08-29 01:08:56 +00:00
Update Tmux related classes
This commit is contained in:
+13
-15
@@ -15,7 +15,7 @@ class Tmux
|
||||
/**
|
||||
* @var \PDO
|
||||
*/
|
||||
public $pdo;
|
||||
public \Closure|\PDO $pdo;
|
||||
|
||||
/**
|
||||
* @var
|
||||
@@ -25,7 +25,7 @@ class Tmux
|
||||
/**
|
||||
* @var \Blacklight\ColorCLI
|
||||
*/
|
||||
protected $colorCli;
|
||||
protected ColorCLI $colorCli;
|
||||
|
||||
/**
|
||||
* Tmux constructor.
|
||||
@@ -235,10 +235,10 @@ class Tmux
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $bytes
|
||||
* @param float $bytes
|
||||
* @return string
|
||||
*/
|
||||
public function decodeSize($bytes): string
|
||||
public function decodeSize(float $bytes): string
|
||||
{
|
||||
$types = ['B', 'KB', 'MB', 'GB', 'TB'];
|
||||
$suffix = 'B';
|
||||
@@ -255,15 +255,15 @@ class Tmux
|
||||
|
||||
/**
|
||||
* @param $pane
|
||||
* @return string
|
||||
* @return string|null
|
||||
*/
|
||||
public function writelog($pane): ?string
|
||||
{
|
||||
$path = NN_LOGS;
|
||||
$getdate = gmdate('Ymd');
|
||||
$getDate = now()->format('Y_m_d');
|
||||
$logs = Settings::settingValue('site.tmux.write_logs') ?? 0;
|
||||
if ($logs === 1) {
|
||||
return "2>&1 | tee -a $path/$pane-$getdate.log";
|
||||
return "2>&1 | tee -a $path/$pane-$getDate.log";
|
||||
}
|
||||
|
||||
return '';
|
||||
@@ -320,9 +320,7 @@ class Tmux
|
||||
*/
|
||||
public function relativeTime($_time): string
|
||||
{
|
||||
$time = Carbon::createFromTimestamp($_time);
|
||||
|
||||
return $time->ago();
|
||||
return Carbon::createFromTimestamp($_time)->ago();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -333,7 +331,7 @@ class Tmux
|
||||
{
|
||||
$returnVal = shell_exec("which $cmd 2>/dev/null");
|
||||
|
||||
return empty($returnVal) ? false : true;
|
||||
return ! empty($returnVal);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -346,7 +344,7 @@ class Tmux
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function proc_query($qry, $bookreqids, $db_name, $ppmax = '', $ppmin = '')
|
||||
public function proc_query($qry, $bookreqids, $db_name, $ppmax = '', $ppmin = ''): bool|string
|
||||
{
|
||||
switch ((int) $qry) {
|
||||
case 1:
|
||||
@@ -471,7 +469,7 @@ class Tmux
|
||||
*/
|
||||
public function stopIfRunning(): bool
|
||||
{
|
||||
if ($this->isRunning() === true) {
|
||||
if ($this->isRunning()) {
|
||||
Settings::query()->where(['section' => 'site', 'subsection' => 'tmux', 'setting' => 'running'])->update(['value' => 0]);
|
||||
$sleep = Settings::settingValue('site.tmux.monitor_delay');
|
||||
$this->colorCli->header('Stopping tmux scripts and waiting '.$sleep.' seconds for all panes to shutdown');
|
||||
@@ -489,7 +487,7 @@ class Tmux
|
||||
*/
|
||||
public function startRunning(): void
|
||||
{
|
||||
if ($this->isRunning() === false) {
|
||||
if (! $this->isRunning()) {
|
||||
Settings::query()->where(['section' => 'site', 'subsection' => 'tmux', 'setting' => 'running'])->update(['value' => 1]);
|
||||
}
|
||||
}
|
||||
@@ -497,7 +495,7 @@ class Tmux
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function cbpmTableQuery()
|
||||
public function cbpmTableQuery(): array
|
||||
{
|
||||
return DB::select(
|
||||
"
|
||||
|
||||
@@ -41,8 +41,7 @@ class TmuxOutput extends Tmux
|
||||
|
||||
/**
|
||||
* @param $runVar
|
||||
*
|
||||
* @throws \Cz\Git\GitException
|
||||
* @return void
|
||||
*/
|
||||
public function updateMonitorPane(&$runVar): void
|
||||
{
|
||||
@@ -126,8 +125,7 @@ class TmuxOutput extends Tmux
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*
|
||||
* @throws \Cz\Git\GitException
|
||||
* @throws \CzProject\GitPhp\GitException
|
||||
*/
|
||||
protected function _getHeader(): string
|
||||
{
|
||||
|
||||
+21
-59
@@ -14,7 +14,10 @@ use Illuminate\Support\Facades\DB;
|
||||
*/
|
||||
class TmuxRun extends Tmux
|
||||
{
|
||||
protected $_dateFormat;
|
||||
/**
|
||||
* @var mixed|string
|
||||
*/
|
||||
protected mixed $_dateFormat;
|
||||
|
||||
/**
|
||||
* TmuxRun constructor.
|
||||
@@ -604,66 +607,25 @@ class TmuxRun extends Tmux
|
||||
$runVar['settings']['seq_timer']
|
||||
);
|
||||
|
||||
switch ($runVar['settings']['binaries_run']) {
|
||||
case 0:
|
||||
$binaries = 'echo "\nbinaries has been disabled/terminated by Binaries"';
|
||||
break;
|
||||
case 1:
|
||||
$binaries = sprintf(
|
||||
'%s %s;',
|
||||
$runVar['scripts']['binaries'],
|
||||
$log
|
||||
);
|
||||
break;
|
||||
default:
|
||||
$binaries = '';
|
||||
}
|
||||
$binaries = match ($runVar['settings']['binaries_run']) {
|
||||
0 => 'echo "\nbinaries has been disabled/terminated by Binaries"',
|
||||
1 => sprintf('%s %s;', $runVar['scripts']['binaries'], $log),
|
||||
default => '',
|
||||
};
|
||||
|
||||
switch ($runVar['settings']['backfill']) {
|
||||
case 0:
|
||||
$backfill = 'echo "backfill is disabled in settings";';
|
||||
break;
|
||||
case 1:
|
||||
$backfill = sprintf(
|
||||
'%s %s %s;',
|
||||
$runVar['scripts']['backfill'],
|
||||
$runVar['settings']['backfill_qty'],
|
||||
$log
|
||||
);
|
||||
break;
|
||||
case 2:
|
||||
$backfill = sprintf(
|
||||
'%s %s %s;',
|
||||
$runVar['scripts']['backfill'],
|
||||
'group',
|
||||
$log
|
||||
);
|
||||
break;
|
||||
case 4:
|
||||
$backfill = sprintf(
|
||||
'%s %s;',
|
||||
$runVar['scripts']['backfill'],
|
||||
$log
|
||||
);
|
||||
break;
|
||||
default:
|
||||
$backfill = '';
|
||||
}
|
||||
$backfill = match ($runVar['settings']['backfill']) {
|
||||
0 => 'echo "backfill is disabled in settings";',
|
||||
1 => sprintf('%s %s %s;', $runVar['scripts']['backfill'], $runVar['settings']['backfill_qty'], $log),
|
||||
2 => sprintf('%s %s %s;', $runVar['scripts']['backfill'], 'group', $log),
|
||||
4 => sprintf('%s %s;', $runVar['scripts']['backfill'], $log),
|
||||
default => '',
|
||||
};
|
||||
|
||||
switch ($runVar['settings']['releases_run']) {
|
||||
case 0:
|
||||
$releases = 'echo PHP_EOL . "releases have been disabled/terminated by Releases"';
|
||||
break;
|
||||
case 1:
|
||||
$releases = sprintf(
|
||||
'%s %s;',
|
||||
$runVar['scripts']['releases'],
|
||||
$log
|
||||
);
|
||||
break;
|
||||
default:
|
||||
$releases = '';
|
||||
}
|
||||
$releases = match ($runVar['settings']['releases_run']) {
|
||||
0 => 'echo PHP_EOL . "releases have been disabled/terminated by Releases"',
|
||||
1 => sprintf('%s %s;', $runVar['scripts']['releases'], $log),
|
||||
default => '',
|
||||
};
|
||||
|
||||
shell_exec("tmux respawnp -t{$runVar['constants']['tmux_session']}:0.2 '$binaries $backfill $releases $date $sleep' 2>&1 1> /dev/null");
|
||||
} elseif (($runVar['killswitch']['pp'] === false) && (time() - $runVar['timers']['timer5'] >= 4800)) {
|
||||
|
||||
@@ -52,7 +52,7 @@ try {
|
||||
$runVar['panes'] = $tRun->getListOfPanes($runVar['constants']);
|
||||
|
||||
//totals per category in db, results by parentID
|
||||
$catcntqry = 'SELECT c.root_categories_id AS parentid, COUNT(r.id) AS count FROM categories c, releases r WHERE r.categories_id = c.id GROUP BY c.root_categories_id';
|
||||
$catCountQuery = 'SELECT c.root_categories_id AS parentid, COUNT(r.id) AS count FROM categories c, releases r WHERE r.categories_id = c.id GROUP BY c.root_categories_id';
|
||||
|
||||
//create timers and set to now
|
||||
$runVar['timers']['timer1'] = $runVar['timers']['timer2'] = $runVar['timers']['timer3'] =
|
||||
@@ -114,7 +114,7 @@ while ($runVar['counts']['iterations'] > 0) {
|
||||
|
||||
//run queries only after time exceeded, these queries can take awhile
|
||||
if ((int) $runVar['counts']['iterations'] === 1 || (time() - $runVar['timers']['timer2'] >= $runVar['settings']['monitor'] && (int) $runVar['settings']['is_running'] === 1)) {
|
||||
$runVar['counts']['proc1'] = $runVar['counts']['proc2'] = $runVar['counts']['proc3'] = $splitqry = $newOldqry = false;
|
||||
$runVar['counts']['proc1'] = $runVar['counts']['proc2'] = $runVar['counts']['proc3'] = $splitQry = $newOldQry = false;
|
||||
$runVar['counts']['now']['total_work'] = 0;
|
||||
$runVar['modsettings']['fix_crap'] = explode(', ', $runVar['settings']['fix_crap']);
|
||||
|
||||
@@ -122,24 +122,22 @@ while ($runVar['counts']['iterations'] > 0) {
|
||||
$timer02 = time();
|
||||
|
||||
try {
|
||||
$splitqry = $tRun->proc_query(4, null, $db_name);
|
||||
$splitQry = $tRun->proc_query(4, null, $db_name);
|
||||
} catch (Exception $e) {
|
||||
echo $e;
|
||||
}
|
||||
try {
|
||||
$newOldqry = $tRun->proc_query(6, null, null);
|
||||
$newOldQry = $tRun->proc_query(6, null, null);
|
||||
} catch (Exception $e) {
|
||||
echo $e;
|
||||
}
|
||||
|
||||
$splitres = (array) Arr::first(DB::select($splitqry));
|
||||
$runVar['timers']['newOld'] = (array) Arr::first(DB::select($newOldqry));
|
||||
$splitRes = (array) Arr::first(DB::select($splitQry));
|
||||
$runVar['timers']['newOld'] = (array) Arr::first(DB::select($newOldQry));
|
||||
|
||||
//assign split query results to main var
|
||||
if (is_array($splitres)) {
|
||||
foreach ($splitres as $splitkey => $split) {
|
||||
$runVar['counts']['now'][$splitkey] = $split;
|
||||
}
|
||||
foreach ($splitRes as $splitKey => $split) {
|
||||
$runVar['counts']['now'][$splitKey] = $split;
|
||||
}
|
||||
|
||||
$runVar['timers']['query']['split_time'] = (time() - $timer02);
|
||||
@@ -208,7 +206,7 @@ while ($runVar['counts']['iterations'] > 0) {
|
||||
$stamp = 'UNIX_TIMESTAMP(MIN(dateadded))';
|
||||
|
||||
switch (true) {
|
||||
case strpos($tbl, 'collections') !== false:
|
||||
case str_contains($tbl, 'collections'):
|
||||
$runVar['counts']['now']['collections_table'] +=
|
||||
getTableRowCount($psTableRowCount, $tbl);
|
||||
$added = DB::select(sprintf('SELECT %s AS dateadded FROM %s', $stamp, $tbl));
|
||||
@@ -218,17 +216,17 @@ while ($runVar['counts']['iterations'] > 0) {
|
||||
$age = $added['dateadded'];
|
||||
}
|
||||
break;
|
||||
case strpos($tbl, 'binaries') !== false:
|
||||
case str_contains($tbl, 'binaries'):
|
||||
$runVar['counts']['now']['binaries_table'] +=
|
||||
getTableRowCount($psTableRowCount, $tbl);
|
||||
break;
|
||||
// This case must come before the 'parts_' one.
|
||||
case strpos($tbl, 'missed_parts') !== false:
|
||||
case str_contains($tbl, 'missed_parts'):
|
||||
$runVar['counts']['now']['missed_parts_table'] +=
|
||||
getTableRowCount($psTableRowCount, $tbl);
|
||||
|
||||
break;
|
||||
case strpos($tbl, 'parts') !== false:
|
||||
case str_contains($tbl, 'parts'):
|
||||
$runVar['counts']['now']['parts_table'] +=
|
||||
getTableRowCount($psTableRowCount, $tbl);
|
||||
break;
|
||||
@@ -263,14 +261,14 @@ while ($runVar['counts']['iterations'] > 0) {
|
||||
}
|
||||
|
||||
// now that we have merged our query data we can unset these to free up memory
|
||||
unset($proc1res, $proc2res, $splitres);
|
||||
unset($proc1res, $proc2res, $splitRes);
|
||||
|
||||
// Zero out any post proc counts when that type of pp has been turned off
|
||||
foreach ($runVar['settings'] as $settingkey => $setting) {
|
||||
if ((int) $setting === 0 && (int) strpos($settingkey, 'process') === 0) {
|
||||
$runVar['counts']['now'][$settingkey] = $runVar['counts']['start'][$settingkey] = 0;
|
||||
foreach ($runVar['settings'] as $settingKey => $setting) {
|
||||
if ((int) $setting === 0 && (int) strpos($settingKey, 'process') === 0) {
|
||||
$runVar['counts']['now'][$settingKey] = $runVar['counts']['start'][$settingKey] = 0;
|
||||
}
|
||||
if ($settingkey === 'fix_names' && (int) $setting === 0) {
|
||||
if ($settingKey === 'fix_names' && (int) $setting === 0) {
|
||||
$runVar['counts']['now']['processrenames'] = $runVar['counts']['start']['processrenames'] = 0;
|
||||
}
|
||||
}
|
||||
@@ -283,7 +281,7 @@ while ($runVar['counts']['iterations'] > 0) {
|
||||
foreach ($runVar['counts']['now'] as $key => $proc) {
|
||||
|
||||
//if key is a process type, add it to total_work
|
||||
if (strpos($key, 'process') === 0) {
|
||||
if (str_starts_with($key, 'process')) {
|
||||
$runVar['counts']['now']['total_work'] += $proc;
|
||||
}
|
||||
|
||||
@@ -408,7 +406,7 @@ while ($runVar['counts']['iterations'] > 0) {
|
||||
|
||||
function errorOnSQL()
|
||||
{
|
||||
(new ColorCLI())->error(PHP_EOL.'Monitor encountered severe errors retrieving process data from MySQL. Please diagnose and try running again.'.PHP_EOL);
|
||||
(new ColorCLI())->error(PHP_EOL.'Monitor encountered severe errors retrieving process data from MySQL. Please diagnose and try running again.'.PHP_EOL);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -418,8 +416,7 @@ function errorOnSQL()
|
||||
*/
|
||||
function getTableRowCount(\PDOStatement $ps, $table)
|
||||
{
|
||||
$success = $ps->execute([':table' => $table]);
|
||||
if ($success) {
|
||||
if ($ps->execute([':table' => $table])) {
|
||||
$result = $ps->fetch();
|
||||
|
||||
return is_numeric($result['count']) ? $result['count'] : 0;
|
||||
|
||||
+13
-13
@@ -7,7 +7,7 @@ use App\Models\Settings;
|
||||
use Blacklight\ColorCLI;
|
||||
use Blacklight\utility\Utility;
|
||||
|
||||
$DIR = base_path().'/misc/update/tmux/';
|
||||
$tmuxPath = base_path().'/misc/update/tmux/';
|
||||
$import = Settings::settingValue('site.tmux.import') ?? 0;
|
||||
$tmux_session = Settings::settingValue('site.tmux.tmux_session') ?? 0;
|
||||
$seq = Settings::settingValue('site.tmux.sequential') ?? 0;
|
||||
@@ -27,17 +27,17 @@ if ($session !== null) {
|
||||
}
|
||||
|
||||
//reset collections dateadded to now if dateadded > delay time check
|
||||
$colorCli->header('Resetting expired collections dateadded to now. This could take some time if many collections need to be reset');
|
||||
$colorCli->header('Resetting collections that have expired to this moment. This could take some time if many collections need to be reset');
|
||||
|
||||
Collection::query()->where('dateadded', '<', now()->subHours($delaytimet))->update(['dateadded' => now()]);
|
||||
|
||||
function writelog($pane)
|
||||
{
|
||||
$path = NN_RES.'logs';
|
||||
$getdate = gmdate('Ymd');
|
||||
$getDate = now()->format('Y_m_d');
|
||||
$logs = Settings::settingValue('site.tmux.write_logs');
|
||||
if ((int) $logs === 1) {
|
||||
return "2>&1 | tee -a $path/$pane-$getdate.log";
|
||||
return "2>&1 | tee -a $path/$pane-$getDate.log";
|
||||
}
|
||||
|
||||
return '';
|
||||
@@ -145,18 +145,18 @@ function window_optimize($tmux_session)
|
||||
exec("tmux splitw -t $tmux_session:3 -v -p 50 'printf \"\033]2;optimize\033\"'");
|
||||
}
|
||||
|
||||
function attach($DIR, $tmux_session)
|
||||
function attach($tmuxPath, $tmux_session)
|
||||
{
|
||||
exec("tmux respawnp -t $tmux_session:0.0 'php ".$DIR."monitor.php'");
|
||||
exec("tmux respawnp -t $tmux_session:0.0 'php ".$tmuxPath."monitor.php'");
|
||||
exec("tmux select-window -t $tmux_session:0; tmux attach-session -d -t $tmux_session");
|
||||
}
|
||||
|
||||
//create tmux session
|
||||
|
||||
$tmuxconfig = $DIR.'tmux.conf';
|
||||
$tmuxconfig = $tmuxPath.'tmux.conf';
|
||||
|
||||
if ((int) $seq === 1) {
|
||||
exec("cd ${DIR}; tmux -f $tmuxconfig new-session -d -s $tmux_session -n Monitor 'printf \"\033]2;\"Monitor\"\033\"'");
|
||||
exec("cd ${tmuxPath}; tmux -f $tmuxconfig new-session -d -s $tmux_session -n Monitor 'printf \"\033]2;\"Monitor\"\033\"'");
|
||||
exec("tmux selectp -t $tmux_session:0.0; tmux splitw -t $tmux_session:0 -h -p 67 'printf \"\033]2;update_releases\033\"'");
|
||||
exec("tmux selectp -t $tmux_session:0.0; tmux splitw -t $tmux_session:0 -v -p 25 'printf \"\033]2;nzb-import\033\"'");
|
||||
|
||||
@@ -164,18 +164,18 @@ if ((int) $seq === 1) {
|
||||
window_post($tmux_session);
|
||||
window_ircscraper($tmux_session);
|
||||
start_apps($tmux_session);
|
||||
attach($DIR, $tmux_session);
|
||||
attach($tmuxPath, $tmux_session);
|
||||
} elseif ((int) $seq === 2) {
|
||||
exec("cd ${DIR}; tmux -f $tmuxconfig new-session -d -s $tmux_session -n Monitor 'printf \"\033]2;\"Monitor\"\033\"'");
|
||||
exec("cd ${tmuxPath}; tmux -f $tmuxconfig new-session -d -s $tmux_session -n Monitor 'printf \"\033]2;\"Monitor\"\033\"'");
|
||||
exec("tmux selectp -t $tmux_session:0.0; tmux splitw -t $tmux_session:0 -h -p 67 'printf \"\033]2;sequential\033\"'");
|
||||
exec("tmux selectp -t $tmux_session:0.0; tmux splitw -t $tmux_session:0 -v -p 25 'printf \"\033]2;nzb-import\033\"'");
|
||||
|
||||
window_stripped_utilities($tmux_session);
|
||||
window_ircscraper($tmux_session);
|
||||
start_apps($tmux_session);
|
||||
attach($DIR, $tmux_session);
|
||||
attach($tmuxPath, $tmux_session);
|
||||
} else {
|
||||
exec("cd ${DIR}; tmux -f $tmuxconfig new-session -d -s $tmux_session -n Monitor 'printf \"\033]2;Monitor\033\"'");
|
||||
exec("cd ${tmuxPath}; tmux -f $tmuxconfig new-session -d -s $tmux_session -n Monitor 'printf \"\033]2;Monitor\033\"'");
|
||||
exec("tmux selectp -t $tmux_session:0.0; tmux splitw -t $tmux_session:0 -h -p 67 'printf \"\033]2;update_binaries\033\"'");
|
||||
exec("tmux selectp -t $tmux_session:0.0; tmux splitw -t $tmux_session:0 -v -p 25 'printf \"\033]2;nzb-import\033\"'");
|
||||
exec("tmux selectp -t $tmux_session:0.2; tmux splitw -t $tmux_session:0 -v -p 67 'printf \"\033]2;backfill\033\"'");
|
||||
@@ -185,5 +185,5 @@ if ((int) $seq === 1) {
|
||||
window_post($tmux_session);
|
||||
window_ircscraper($tmux_session);
|
||||
start_apps($tmux_session);
|
||||
attach($DIR, $tmux_session);
|
||||
attach($tmuxPath, $tmux_session);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user