mirror of
https://github.com/torrentpier/torrentpier-lts.git
synced 2025-02-28 15:10:54 +03:00
Cron subsystem rework (#206)
This commit is contained in:
parent
98a79565d1
commit
1b304e8bc5
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
if (isset($_REQUEST['GLOBALS'])) die();
|
if (isset($_REQUEST['GLOBALS'])) die();
|
||||||
|
|
||||||
ignore_user_abort(true);
|
|
||||||
define('TIMESTART', utime());
|
define('TIMESTART', utime());
|
||||||
define('TIMENOW', time());
|
define('TIMENOW', time());
|
||||||
|
|
||||||
|
@ -254,11 +254,9 @@ class sql_db
|
|||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch current row
|
* Fetch current row
|
||||||
@ -271,11 +269,9 @@ class sql_db
|
|||||||
{
|
{
|
||||||
return isset($row[$field_name]) ? $row[$field_name] : false;
|
return isset($row[$field_name]) ? $row[$field_name] : false;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
return $row;
|
return $row;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Alias of sql_fetchrow()
|
* Alias of sql_fetchrow()
|
||||||
@ -531,11 +527,9 @@ class sql_db
|
|||||||
{
|
{
|
||||||
return array('code' => mysql_errno($this->link), 'message' => mysql_error($this->link));
|
return array('code' => mysql_errno($this->link), 'message' => mysql_error($this->link));
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
return array('code' => '', 'message' => 'not connected');
|
return array('code' => '', 'message' => 'not connected');
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Close sql connection
|
* Close sql connection
|
||||||
|
@ -22,7 +22,6 @@ if ($cron_jobs)
|
|||||||
if ($job['disable_board'])
|
if ($job['disable_board'])
|
||||||
{
|
{
|
||||||
cron_disable_board();
|
cron_disable_board();
|
||||||
sleep(10);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,6 @@ function cron_track_running ($mode)
|
|||||||
//
|
//
|
||||||
if (cron_get_file_lock())
|
if (cron_get_file_lock())
|
||||||
{
|
{
|
||||||
ignore_user_abort(true);
|
|
||||||
register_shutdown_function('cron_release_file_lock');
|
register_shutdown_function('cron_release_file_lock');
|
||||||
register_shutdown_function('cron_enable_board');
|
register_shutdown_function('cron_enable_board');
|
||||||
|
|
||||||
|
@ -114,8 +114,6 @@ foreach ($cron_jobs as $job)
|
|||||||
LIMIT 1
|
LIMIT 1
|
||||||
");
|
");
|
||||||
|
|
||||||
sleep(1);
|
|
||||||
|
|
||||||
if (utime() - TIMESTART > 600)
|
if (utime() - TIMESTART > 600)
|
||||||
{
|
{
|
||||||
return; // чтобы daily скрипты не блокировали надолго interval'ные
|
return; // чтобы daily скрипты не блокировали надолго interval'ные
|
||||||
|
@ -31,10 +31,6 @@ if ($poll_max_days = (int) $bb_cfg['poll_max_days'])
|
|||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!($start_id % ($per_cycle*10)))
|
|
||||||
{
|
|
||||||
sleep(1);
|
|
||||||
}
|
|
||||||
$start_id += $per_cycle;
|
$start_id += $per_cycle;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,6 +52,4 @@ while (true)
|
|||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
sleep(3);
|
|
||||||
}
|
}
|
@ -34,8 +34,6 @@ DB()->query("
|
|||||||
DB()->unlock();
|
DB()->unlock();
|
||||||
// ############################ Tables UNLOCKED ##############################
|
// ############################ Tables UNLOCKED ##############################
|
||||||
|
|
||||||
sleep(5);
|
|
||||||
|
|
||||||
// Delete staled sessions
|
// Delete staled sessions
|
||||||
DB()->query("
|
DB()->query("
|
||||||
DELETE s
|
DELETE s
|
||||||
|
@ -83,11 +83,6 @@ while (true)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!($start_id % ($per_cycle*10)))
|
|
||||||
{
|
|
||||||
sleep(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
$start_id += $per_cycle;
|
$start_id += $per_cycle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +41,6 @@ function run_jobs($jobs)
|
|||||||
END
|
END
|
||||||
WHERE cron_id IN ($jobs)
|
WHERE cron_id IN ($jobs)
|
||||||
");
|
");
|
||||||
sleep(3);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -677,16 +677,11 @@ function ocelot_send_request ($get, $max_attempts = 1, &$err = false)
|
|||||||
global $bb_cfg;
|
global $bb_cfg;
|
||||||
|
|
||||||
$header = "GET /$get HTTP/1.1\r\nConnection: Close\r\n\r\n";
|
$header = "GET /$get HTTP/1.1\r\nConnection: Close\r\n\r\n";
|
||||||
$attempts = $sleep = $success = $response = 0;
|
$attempts = $success = $response = 0;
|
||||||
$start_time = microtime(true);
|
$start_time = microtime(true);
|
||||||
|
|
||||||
while (!$success && $attempts++ < $max_attempts)
|
while (!$success && $attempts++ < $max_attempts)
|
||||||
{
|
{
|
||||||
if ($sleep)
|
|
||||||
{
|
|
||||||
sleep($sleep);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send request
|
// Send request
|
||||||
$file = fsockopen($bb_cfg['ocelot']['host'], $bb_cfg['ocelot']['port'], $error_num, $error_string);
|
$file = fsockopen($bb_cfg['ocelot']['host'], $bb_cfg['ocelot']['port'], $error_num, $error_string);
|
||||||
if ($file)
|
if ($file)
|
||||||
@ -694,14 +689,12 @@ function ocelot_send_request ($get, $max_attempts = 1, &$err = false)
|
|||||||
if (fwrite($file, $header) === false)
|
if (fwrite($file, $header) === false)
|
||||||
{
|
{
|
||||||
$err = "Failed to fwrite()";
|
$err = "Failed to fwrite()";
|
||||||
$sleep = 3;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$err = "Failed to fsockopen() - $error_num - $error_string";
|
$err = "Failed to fsockopen() - $error_num - $error_string";
|
||||||
$sleep = 6;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -480,10 +480,7 @@ if ((empty($_POST) && !defined('IN_ADMIN') && !defined('IN_AJAX') && !file_exist
|
|||||||
if (DB()->get_lock('cron', 1))
|
if (DB()->get_lock('cron', 1))
|
||||||
{
|
{
|
||||||
bb_log(date('H:i:s - ') . getmypid() .' --x- DB-LOCK OBTAINED !!!!!!!!!!!!!!!!!'. LOG_LF, CRON_LOG_DIR .'cron_check');
|
bb_log(date('H:i:s - ') . getmypid() .' --x- DB-LOCK OBTAINED !!!!!!!!!!!!!!!!!'. LOG_LF, CRON_LOG_DIR .'cron_check');
|
||||||
|
|
||||||
sleep(2);
|
|
||||||
require(CRON_DIR .'cron_init.php');
|
require(CRON_DIR .'cron_init.php');
|
||||||
|
|
||||||
DB()->release_lock('cron');
|
DB()->release_lock('cron');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user