|
95 | 95 | echo "\n";
|
96 | 96 |
|
97 | 97 | // создаем табличку cyclesRun, если её нет
|
98 |
| -SQLExec('CREATE TABLE IF NOT EXISTS `cyclesRun` (`KEYWORD` char(100) NOT NULL,`DATAVALUE` char(255) NOT NULL,PRIMARY KEY (`KEYWORD`)) ENGINE=MEMORY DEFAULT CHARSET=utf8;'); |
| 98 | +SQLExec('CREATE TABLE IF NOT EXISTS `cached_cycles` (`TITLE` char(100) NOT NULL,`VALUE` char(255) NOT NULL,PRIMARY KEY (`TITLE`)) ENGINE=MEMORY DEFAULT CHARSET=utf8;'); |
| 99 | +SQLExec('DROP TABLE IF EXISTS cyclesRun;'); |
| 100 | + |
99 | 101 |
|
100 | 102 | $old_mask = umask(0);
|
101 | 103 | if (is_dir(ROOT . 'cached')) {
|
|
260 | 262 | $qry = "1 AND (TITLE LIKE 'cycle%Run' OR TITLE LIKE 'cycle%Control' OR TITLE LIKE 'cycle%Disabled' OR TITLE LIKE 'cycle%AutoRestart')";
|
261 | 263 | $thisCompObject = getObject('ThisComputer');
|
262 | 264 | $cycles_records = SQLSelect("SELECT properties.* FROM properties WHERE $qry ORDER BY TITLE");
|
| 265 | +SQLExec("DELETE FROM cached_cycles"); |
| 266 | + |
263 | 267 | $total = count($cycles_records);
|
264 | 268 | for ($i = 0; $i < $total; $i++) {
|
265 | 269 | DebMes("Removing property ThisComputer.$property (object ".$thisCompObject->id.")",'threads');
|
|
381 | 385 | if ((time() - $last_cycles_control_check) >= 5 || !empty($result)) {
|
382 | 386 |
|
383 | 387 | $last_cycles_control_check = time();
|
| 388 | + $cyclesControls=$cyclesTimestamps=array(); |
| 389 | + $tmpcyclesTimestamps=SQLSelect("SELECT * FROM cached_cycles;"); |
| 390 | + |
| 391 | + $total = count($tmpcyclesTimestamps); |
| 392 | + foreach ($tmpcyclesTimestamps as $k => $v) { |
| 393 | + if (strpos($v['TITLE'],'Run') !== FALSE) { |
| 394 | + $cyclesTimestamps[$v['TITLE']] = $v['VALUE']; |
| 395 | + } else if (strpos($v['TITLE'],'Control') !== FALSE) { |
| 396 | + $cyclesControls[$v['TITLE']] = $v['VALUE']; |
| 397 | + } |
| 398 | + } |
384 | 399 |
|
385 |
| - $qry = "OBJECT_ID=" . $thisComputerObject->id . " AND (TITLE LIKE 'cycle%Run' OR TITLE LIKE 'cycle%Control')"; |
386 |
| - $cycles = SQLSelect("SELECT properties.* FROM properties WHERE $qry ORDER BY TITLE"); |
387 |
| - |
388 |
| - $total = count($cycles); |
389 | 400 | $seen = array();
|
390 | 401 | for ($i = 0; $i < $total; $i++) {
|
391 |
| - $title = $cycles[$i]['TITLE']; |
| 402 | + $title = $tmpcyclesTimestamps[$i]['TITLE']; |
392 | 403 | $title = preg_replace('/Run$/', '', $title);
|
393 | 404 | $title = preg_replace('/Control$/', '', $title);
|
394 | 405 | if (isset($seen[$title])) {
|
395 | 406 | continue;
|
396 | 407 | }
|
397 | 408 | $seen[$title] = 1;
|
398 |
| - $control = getGlobal($title . 'Control'); |
| 409 | + $control=''; |
| 410 | + |
| 411 | + if (isset($cyclesControls[$title . 'Control'])) $control = $cyclesControls[$title . 'Control']; |
399 | 412 | if ($control != '') {
|
400 | 413 | DebMes("Got control command '$control' for " . $title, 'threads');
|
401 | 414 | if ($control == 'stop') {
|
|
410 | 423 | }
|
411 | 424 |
|
412 | 425 | $is_running = array();
|
413 |
| - $tmpcyclesTimestamps=SQLSelect("SELECT * FROM cyclesRun;"); |
414 |
| - foreach ($tmpcyclesTimestamps as $k => $v) $cyclesTimestamps[$v['KEYWORD']] = $v['DATAVALUE']; |
415 |
| - |
| 426 | + |
416 | 427 | foreach ($threads->commandLines as $id => $cmd) {
|
417 | 428 | if (preg_match('/(cycle_.+?)\.php/is', $cmd, $m)) {
|
418 | 429 | $title = $m[1];
|
|
422 | 433 | DebMes("Adding $title to auto-recovery list", 'threads');
|
423 | 434 | $auto_restarts[] = $title;
|
424 | 435 | }
|
| 436 | + $cycle_updated_timestamp=$cyclesTimestamps[$title.'Run']; |
425 | 437 |
|
426 |
| - //$cycle_updated_timestamp = getGlobal($title . 'Run'); |
427 |
| - $cycle_updated_timestamp=$cyclesTimestamps[strtolower('MJD:ThisComputer.'.$title.'Run')]; |
428 |
| - if (!isset($to_start[$title]) && |
429 |
| - $cycle_updated_timestamp && |
430 |
| - in_array($title, $auto_restarts) && |
431 |
| - ((time() - $cycle_updated_timestamp) > 30 * 60) |
432 |
| - ) { // |
| 438 | + if (!$to_start[$title] && $cycle_updated_timestamp && in_array($title, $auto_restarts) && ((time() - $cycle_updated_timestamp) > 30 * 60)) { // |
433 | 439 | DebMes("Looks like $title is dead (updated: ".date('Y-m-d H:i:s',$cycle_updated_timestamp)."). Need to recovery", 'threads');
|
434 | 440 | registerError('cycle_hang', $title);
|
435 | 441 | setGlobal($title . 'Control', 'restart');
|
|
438 | 444 | }
|
439 | 445 | }
|
440 | 446 |
|
| 447 | + |
441 | 448 | if (isRebootRequired()) {
|
442 | 449 | if (!$reboot_timer) {
|
443 | 450 | $reboot_timer = time();
|
|
0 commit comments