<commit_before>#!/usr/bin/php -q
<?php
require_once('../../../connections/parameters.php');
require_once('../../../global_functions.php');
require_once('../../../cron_functions.php');

//RUN AS CRON EVERY 30SECONDS
//WRITE TO A LOG FILE WITH DATE IN FILENAME
//HAVE A CRON TO DELETE LOGS OLDER THAN A DAY

try {
    /////////////////////////////
    // Parameters
    /////////////////////////////

    $db = new dbWrapper_v3($hostname_gds_cron, $username_gds_cron, $password_gds_cron, $database_gds_cron, true);
    if (empty($db)) throw new Exception('No DB!');

    $memcached = new Cache(NULL, NULL, $localDev);

    set_time_limit(0);

    $timeStarted = time();

    //Grab active tasks
    $taskListActive = $db->q("SELECT
            `cron_id`,
            `cron_task_group`,
            `cron_task`,
            `cron_user`,
            `cron_blocking`,
            `cron_date`
        FROM `cron_tasks`
        WHERE `cron_status` = 1
        ORDER BY `cron_date` ASC;"
    );

    //Parse active tasks, abort if any of the active tasks are blocking
    if (!empty($taskListActive)) {
        echo "<h2>Active Tasks</h2>";
        echo "<table border='1' cellspacing='1' cellpadding='5'>";
        echo "<tr>
                    <td><strong>ID</strong></td>
                    <td><strong>Task</strong></td>
                    <td><strong>User</strong></td>
                    <td><strong>Blocking</strong></td>
                    <td><strong>Date</strong></td>
                </tr>
                ";

        $blockingTasks = false;
        foreach ($taskListActive as $key => $value) {
            $task = empty($value['cron_task_group'])
                ? $value['cron_task']
                : $value['cron_task_group'] . ' -- ' . $value['cron_task'];

            $user = !empty($value['cron_user'])
                ? $value['cron_user']
                : 'cron_job';

            echo "<tr>
                    <td>{$value['cron_id']}</td>
                    <td>{$task}</td>
                    <td>{$user}</td>
                    <td>{$value['cron_blocking']}</td>
                    <td>{$value['cron_date']}</td>
                </tr>
                ";

            if ($value['cron_blocking'] == 1) $blockingTasks = true;
        }
        echo "</table>";

        if ($blockingTasks) throw new Exception("Blocking tasks are currently running!");
    }

    //Grab the non-active task list
    $taskList = $db->q("SELECT
          `cron_id`,
          `cron_task_group`,
          `cron_task`,
          `cron_parameters`,
          `cron_priority`,
          `cron_blocking`,
          `cron_user`,
          `cron_date`
        FROM `cron_tasks`
        WHERE `cron_status` = 0
        ORDER BY `cron_priority` DESC, `cron_date` ASC
        LIMIT 0, 100;"
    );<commit_msg>Order crons by priority, blocking, then date added<commit_after>#!/usr/bin/php -q
<?php
require_once('../../../connections/parameters.php');
require_once('../../../global_functions.php');
require_once('../../../cron_functions.php');

//RUN AS CRON EVERY 30SECONDS
//WRITE TO A LOG FILE WITH DATE IN FILENAME
//HAVE A CRON TO DELETE LOGS OLDER THAN A DAY

try {
    /////////////////////////////
    // Parameters
    /////////////////////////////

    $db = new dbWrapper_v3($hostname_gds_cron, $username_gds_cron, $password_gds_cron, $database_gds_cron, true);
    if (empty($db)) throw new Exception('No DB!');

    $memcached = new Cache(NULL, NULL, $localDev);

    set_time_limit(0);

    $timeStarted = time();

    //Grab active tasks
    $taskListActive = $db->q("SELECT
            `cron_id`,
            `cron_task_group`,
            `cron_task`,
            `cron_user`,
            `cron_blocking`,
            `cron_date`
        FROM `cron_tasks`
        WHERE `cron_status` = 1
        ORDER BY `cron_date` ASC;"
    );

    //Parse active tasks, abort if any of the active tasks are blocking
    if (!empty($taskListActive)) {
        echo "<h2>Active Tasks</h2>";
        echo "<table border='1' cellspacing='1' cellpadding='5'>";
        echo "<tr>
                    <td><strong>ID</strong></td>
                    <td><strong>Task</strong></td>
                    <td><strong>User</strong></td>
                    <td><strong>Blocking</strong></td>
                    <td><strong>Date</strong></td>
                </tr>
                ";

        $blockingTasks = false;
        foreach ($taskListActive as $key => $value) {
            $task = empty($value['cron_task_group'])
                ? $value['cron_task']
                : $value['cron_task_group'] . ' -- ' . $value['cron_task'];

            $user = !empty($value['cron_user'])
                ? $value['cron_user']
                : 'cron_job';

            echo "<tr>
                    <td>{$value['cron_id']}</td>
                    <td>{$task}</td>
                    <td>{$user}</td>
                    <td>{$value['cron_blocking']}</td>
                    <td>{$value['cron_date']}</td>
                </tr>
                ";

            if ($value['cron_blocking'] == 1) $blockingTasks = true;
        }
        echo "</table>";

        if ($blockingTasks) throw new Exception("Blocking tasks are currently running!");
    }

    //Grab the non-active task list
    $taskList = $db->q("SELECT
          `cron_id`,
          `cron_task_group`,
          `cron_task`,
          `cron_parameters`,
          `cron_priority`,
          `cron_blocking`,
          `cron_user`,
          `cron_date`
        FROM `cron_tasks`
        WHERE `cron_status` = 0
        ORDER BY `cron_priority` DESC, `cron_blocking` ASC, `cron_date` ASC
        LIMIT 0, 100;"
    );
{'fraction_non_alphanumeric': 0.17436530324400565, 'fraction_numerical': 0.005641748942172073, 'mean_word_length': 1.6435228331780056, 'pattern_counts': {'":': 0, '<': 81, '<?xml version=': 0, '>': 85, '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': '4659812', 'n_tokens_mistral': 1829, 'n_tokens_neox': 1712, 'n_words': 353}