Cron subsystem rework. Environments.

This commit is contained in:
Yuriy Pikhtarev 2017-06-10 03:11:10 +03:00
commit 18aeb3e9d5
No known key found for this signature in database
GPG key ID: 3A9B5A757B48ECC6
91 changed files with 865 additions and 834 deletions

View file

@ -1,2 +0,0 @@
order allow,deny
deny from all

View file

@ -43,8 +43,7 @@ if ($cron_jobs) {
foreach ($cron_jobs as $job) {
if ($job['disable_board']) {
cron_disable_board();
sleep(10);
TorrentPier\Helpers\CronHelper::disableBoard();
break;
}
}
@ -52,7 +51,7 @@ if ($cron_jobs) {
require(CRON_DIR . 'cron_run.php');
// Update cron_last_check
bb_update_config(array('cron_last_check' => (TIMENOW + 10)));
bb_update_config(array('cron_last_check' => TIMENOW + 10));
} else {
bb_log(date('H:i:s - ') . getmypid() . ' --x- no active jobs found ----------------------------------------------' . LOG_LF, CRON_LOG_DIR . '/cron_check');
}

View file

@ -1,82 +0,0 @@
<?php
/**
* MIT License
*
* Copyright (c) 2005-2017 TorrentPier
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
if (!defined('BB_ROOT')) {
die(basename(__FILE__));
}
//
// Functions
//
function cron_get_file_lock()
{
$lock_obtained = false;
if (file_exists(CRON_ALLOWED)) {
# bb_log(date('H:i:s - ') . getmypid() .' -x-- FILE-LOCK try'. LOG_LF, CRON_LOG_DIR .'/cron_check');
$lock_obtained = @rename(CRON_ALLOWED, CRON_RUNNING);
} elseif (file_exists(CRON_RUNNING)) {
cron_release_deadlock();
} elseif (!file_exists(CRON_ALLOWED) && !file_exists(CRON_RUNNING)) {
file_write('', CRON_ALLOWED);
$lock_obtained = @rename(CRON_ALLOWED, CRON_RUNNING);
}
return $lock_obtained;
}
function cron_track_running($mode)
{
@define('CRON_STARTMARK', TRIGGERS_DIR . '/cron_started_at_' . date('Y-m-d_H-i-s') . '_by_pid_' . getmypid());
if ($mode == 'start') {
cron_touch_lock_file(CRON_RUNNING);
file_write('', CRON_STARTMARK);
} elseif ($mode == 'end') {
@unlink(CRON_STARTMARK);
}
}
//
// Run cron
//
if (cron_get_file_lock()) {
ignore_user_abort(true);
register_shutdown_function('cron_release_file_lock');
register_shutdown_function('cron_enable_board');
# bb_log(date('H:i:s - ') . getmypid() .' --x- FILE-LOCK OBTAINED ###############'. LOG_LF, CRON_LOG_DIR .'/cron_check');
cron_track_running('start');
require(CRON_DIR . 'cron_check.php');
cron_track_running('end');
}
if (defined('IN_CRON')) {
bb_log(date('H:i:s - ') . getmypid() . ' --x- ALL jobs FINISHED *************************************************' . LOG_LF, CRON_LOG_DIR . '/cron_check');
}

View file

@ -132,8 +132,6 @@ foreach ($cron_jobs as $job) {
LIMIT 1
");
sleep(1);
if (utime() - TIMESTART > 600) {
return; // чтобы daily скрипты не блокировали надолго interval'ные
}

View file

@ -1,2 +0,0 @@
order allow,deny
deny from all

View file

@ -50,12 +50,11 @@ if ($poll_max_days = (int)$bb_cfg['poll_max_days']) {
WHERE topic_id BETWEEN $start_id AND $end_id
AND vote_dt < DATE_SUB(NOW(), INTERVAL $poll_max_days DAY)
");
if ($end_id > $finish_id) {
break;
}
if (!($start_id % ($per_cycle * 10))) {
sleep(1);
}
$start_id += $per_cycle;
}
}

View file

@ -70,6 +70,4 @@ while (true) {
if (count($prune_users) < $users_per_cycle) {
break;
}
sleep(3);
}

View file

@ -59,8 +59,6 @@ DB()->query("
DB()->unlock();
// ############################ Tables UNLOCKED ##############################
sleep(5);
// Delete staled sessions
DB()->query("
DELETE s

View file

@ -43,7 +43,7 @@ DB()->query("CREATE TABLE " . NEW_BB_BT_LAST_USERSTAT . " LIKE " . BB_BT_LAST_US
DB()->expect_slow_query(600);
// Update dlstat (part 1)
if ($tr_cfg['update_dlstat']) {
if ($bb_cfg['tracker']['update_dlstat']) {
// ############################ Tables LOCKED ################################
DB()->lock(array(
BB_BT_TRACKER,
@ -80,16 +80,16 @@ DB()->query("
");
// Clean peers table
if ($tr_cfg['autoclean']) {
if ($bb_cfg['tracker']['autoclean']) {
$announce_interval = max((int)$bb_cfg['announce_interval'], 60);
$expire_factor = max((float)$tr_cfg['expire_factor'], 1);
$expire_factor = max((float)$bb_cfg['tracker']['expire_factor'], 1);
$peer_expire_time = TIMENOW - floor($announce_interval * $expire_factor);
DB()->query("DELETE FROM " . BB_BT_TRACKER . " WHERE update_time < $peer_expire_time");
}
// Update dlstat (part 2)
if ($tr_cfg['update_dlstat']) {
if ($bb_cfg['tracker']['update_dlstat']) {
// Set "only 1 seeder" bonus
DB()->query("
UPDATE

View file

@ -97,10 +97,6 @@ while (true) {
break;
}
if (!($start_id % ($per_cycle * 10))) {
sleep(1);
}
$start_id += $per_cycle;
}