<commit_before><?php
class Kwf_Controller_Action_Cli_Web_MaintenanceJobsController extends Kwf_Controller_Action_Cli_Abstract
{
    public static function getHelp()
    {
        return "execute mainteanance commands, should be run by process-control";
    }

    public function runAction()
    {
        $debug = $this->_getParam('debug');

        if (file_exists('temp/shutdown-maintenance')) {
            unlink('temp/shutdown-maintenance');
        }

        $lastDailyRun = null;
        if (file_exists('temp/maintenance-daily-run')) {
            $lastDailyRun = file_get_contents('temp/maintenance-daily-run');
            if ($debug) echo "last daily run: ".date('Y-m-d H:i:s', $lastDailyRun)."\n";
        }

        $lastHourlyRun = null;
        if (file_exists('temp/maintenance-hourly-run')) {
            $lastHourlyRun = file_get_contents('temp/maintenance-hourly-run');
            if ($debug) echo "last hourly run: ".date('Y-m-d H:i:s', $lastHourlyRun)."\n";
        }

        $dailyMaintenanceWindowStart = "01:00"; //don't set before 00:00
        $dailyMaintenanceWindowEnd = "05:00";

        $nextDailyRun = null;
        $lastMinutelyRun = null;
        while (true) {
            if (!$nextDailyRun) {
                if ($lastDailyRun && $lastDailyRun > strtotime($dailyMaintenanceWindowStart)) { //today already run
                    //maintenance window of tomorrow
                    $nextDailyRun = rand(strtotime("tomorrow $dailyMaintenanceWindowStart"), strtotime("tomorrow $dailyMaintenanceWindowEnd"));
                } else { //not yet run or today not yet run
                    if (time() < strtotime($dailyMaintenanceWindowEnd)) { //window not yet over for today
                        //maintenance window of today
                        $nextDailyRun = rand(max(time(), strtotime($dailyMaintenanceWindowStart)), strtotime($dailyMaintenanceWindowEnd));
                    } else {
                        //maintenance window of tomorrow
                        $nextDailyRun = rand(strtotime("tomorrow $dailyMaintenanceWindowStart"), strtotime("tomorrow $dailyMaintenanceWindowEnd"));
                    }
                }
                if ($debug) echo "Next daily run: ".date('Y-m-d H:i:s', $nextDailyRun)."\n";
            }

            Kwf_Util_Maintenance_Dispatcher::executeJobs(Kwf_Util_Maintenance_Job_Abstract::FREQUENCY_SECONDS, $debug);
            if (!$lastMinutelyRun || time()-$lastMinutelyRun > 60) {
                $lastMinutelyRun = time();
                Kwf_Util_Maintenance_Dispatcher::executeJobs(Kwf_Util_Maintenance_Job_Abstract::FREQUENCY_MINUTELY, $debug);

                //discard connection to database to reconnect on next job run
                //avoids problems with auto closed connections due to inactivity
                Kwf_Model_Abstract::clearAllRows();
                Kwf_Model_Abstract::clearInstances();
                Kwf_Registry::getInstance()->offsetUnset('db');
                Kwf_Registry::getInstance()->offsetUnset('dao');
            }
<commit_msg>Unset Db-Connection only when gc_collect_cycles is possible<commit_after><?php
class Kwf_Controller_Action_Cli_Web_MaintenanceJobsController extends Kwf_Controller_Action_Cli_Abstract
{
    public static function getHelp()
    {
        return "execute mainteanance commands, should be run by process-control";
    }

    public function runAction()
    {
        $debug = $this->_getParam('debug');

        if (file_exists('temp/shutdown-maintenance')) {
            unlink('temp/shutdown-maintenance');
        }

        $lastDailyRun = null;
        if (file_exists('temp/maintenance-daily-run')) {
            $lastDailyRun = file_get_contents('temp/maintenance-daily-run');
            if ($debug) echo "last daily run: ".date('Y-m-d H:i:s', $lastDailyRun)."\n";
        }

        $lastHourlyRun = null;
        if (file_exists('temp/maintenance-hourly-run')) {
            $lastHourlyRun = file_get_contents('temp/maintenance-hourly-run');
            if ($debug) echo "last hourly run: ".date('Y-m-d H:i:s', $lastHourlyRun)."\n";
        }

        $dailyMaintenanceWindowStart = "01:00"; //don't set before 00:00
        $dailyMaintenanceWindowEnd = "05:00";

        $nextDailyRun = null;
        $lastMinutelyRun = null;
        while (true) {
            if (!$nextDailyRun) {
                if ($lastDailyRun && $lastDailyRun > strtotime($dailyMaintenanceWindowStart)) { //today already run
                    //maintenance window of tomorrow
                    $nextDailyRun = rand(strtotime("tomorrow $dailyMaintenanceWindowStart"), strtotime("tomorrow $dailyMaintenanceWindowEnd"));
                } else { //not yet run or today not yet run
                    if (time() < strtotime($dailyMaintenanceWindowEnd)) { //window not yet over for today
                        //maintenance window of today
                        $nextDailyRun = rand(max(time(), strtotime($dailyMaintenanceWindowStart)), strtotime($dailyMaintenanceWindowEnd));
                    } else {
                        //maintenance window of tomorrow
                        $nextDailyRun = rand(strtotime("tomorrow $dailyMaintenanceWindowStart"), strtotime("tomorrow $dailyMaintenanceWindowEnd"));
                    }
                }
                if ($debug) echo "Next daily run: ".date('Y-m-d H:i:s', $nextDailyRun)."\n";
            }

            Kwf_Util_Maintenance_Dispatcher::executeJobs(Kwf_Util_Maintenance_Job_Abstract::FREQUENCY_SECONDS, $debug);
            if (!$lastMinutelyRun || time()-$lastMinutelyRun > 60) {
                $lastMinutelyRun = time();
                Kwf_Util_Maintenance_Dispatcher::executeJobs(Kwf_Util_Maintenance_Job_Abstract::FREQUENCY_MINUTELY, $debug);

                //discard connection to database to reconnect on next job run
                //avoids problems with auto closed connections due to inactivity
                if (function_exists('gc_collect_cycles()')) {
                    Kwf_Model_Abstract::clearAllRows();
                    Kwf_Model_Abstract::clearInstances();
                    gc_collect_cycles();
                    Kwf_Registry::getInstance()->offsetUnset('db');
                    Kwf_Registry::getInstance()->offsetUnset('dao');
                }
            }
{'fraction_non_alphanumeric': 0.11280101394169835, 'fraction_numerical': 0.004435994930291508, 'mean_word_length': 2.298328108672936, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2273580', 'n_tokens_mistral': 1861, 'n_tokens_neox': 1694, 'n_words': 341}