コード例 #1
0
ファイル: processsubmissions.php プロジェクト: rpshaw/CDash
function ProcessSubmissions($projectid)
{
    $qs = "SELECT id, filename, filesize, filemd5sum, attempts FROM submission " . "WHERE projectid='" . $projectid . "' AND status=0 ORDER BY id LIMIT 1";
    $query = pdo_query($qs);
    add_last_sql_error("ProcessSubmissions-1");
    $iterations = 0;
    $mypid = getmypid();
    @($sleep_in_loop = $_GET['sleep_in_loop']);
    @($intentional_nonreturning_submit = $_GET['intentional_nonreturning_submit']);
    $n = pdo_num_rows($query);
    while ($n > 0) {
        if ($sleep_in_loop) {
            sleep($sleep_in_loop);
        }
        $query_array = pdo_fetch_array($query);
        add_last_sql_error("ProcessSubmissions-1.5");
        pdo_free_result($query);
        // Verify that *this* process still owns the lock.
        //
        // If not, log a message and return, presuming that the process that took
        // the lock is now looping over pending submissions.
        //
        if (!ProcessOwnsLock($projectid, $mypid)) {
            add_log("pid '{$mypid}' does not own lock anymore: abandoning loop...", "ProcessSubmissions", LOG_INFO, $projectid);
            return false;
        }
        $submission_id = $query_array['id'];
        $filename = $query_array['filename'];
        $new_attempts = $query_array['attempts'] + 1;
        $md5 = $query_array['filemd5sum'];
        // Mark the submissionprocessing table each time through the loop so that
        // we do not become known as an "apparently stalled" processor...
        //
        SetLockLastUpdatedTime($projectid);
        global $CDASH_SUBMISSION_PROCESSING_MAX_ATTEMPTS;
        if ($new_attempts > $CDASH_SUBMISSION_PROCESSING_MAX_ATTEMPTS) {
            add_log("Too many attempts to process '" . $filename . "'", "ProcessSubmissions", LOG_ERR, $projectid);
            $new_status = 5;
            // done, called do_submit too many times already
        } else {
            // Mark it as status=1 (processing) and record started time:
            //
            $now_utc = gmdate(FMT_DATETIMESTD);
            pdo_query("UPDATE submission SET status=1, started='{$now_utc}', " . "lastupdated='{$now_utc}', attempts={$new_attempts} " . "WHERE id='" . $submission_id . "'");
            add_last_sql_error("ProcessSubmissions-2");
            // Record id in global so that we can mark it as "error status" if we
            // get thrown to the error handler...
            //
            global $PHP_ERROR_SUBMISSION_ID;
            $PHP_ERROR_SUBMISSION_ID = $submission_id;
            if ($intentional_nonreturning_submit) {
                // simulate "error occurred" during do_submit: status will be set
                // to 4 in error handler...
                trigger_error('ProcessFile: intentional_nonreturning_submit is on', E_USER_ERROR);
            }
            $new_status = ProcessFile($projectid, $filename, $md5);
        }
        $PHP_ERROR_SUBMISSION_ID = 0;
        // Mark it as done with $new_status and record finished time:
        //
        $now_utc = gmdate(FMT_DATETIMESTD);
        pdo_query("UPDATE submission SET status={$new_status}, finished='{$now_utc}', " . "lastupdated='{$now_utc}' WHERE id='" . $submission_id . "'");
        add_last_sql_error("ProcessSubmissions-3");
        // Query for more... Continue processing while there are records to
        // process:
        //
        $query = pdo_query($qs);
        add_last_sql_error("ProcessSubmissions-4");
        $n = pdo_num_rows($query);
        $iterations = $iterations + 1;
    }
    return true;
}
コード例 #2
0
function ProcessSubmissions($projectid, $mypid, $multi = false)
{
    $iterations = 0;
    @($sleep_in_loop = $_GET['sleep_in_loop']);
    @($intentional_nonreturning_submit = $_GET['intentional_nonreturning_submit']);
    $query_array = GetNextSubmission($projectid);
    if ($query_array === false) {
        return false;
    }
    $n = count($query_array);
    while ($n > 0) {
        if ($sleep_in_loop) {
            sleep($sleep_in_loop);
        }
        // Verify that *this* process still owns the lock.
        //
        // If not, log a message and return, presuming that the process
        // that took the lock is now looping over pending submissions.
        //
        if (!$multi && !ProcessOwnsLock($projectid, $mypid)) {
            add_log("pid '{$mypid}' does not own lock anymore: abandoning loop...", 'ProcessSubmissions', LOG_INFO, $projectid);
            return false;
        }
        $submission_id = $query_array['id'];
        $filename = $query_array['filename'];
        $new_attempts = $query_array['attempts'] + 1;
        $md5 = $query_array['filemd5sum'];
        // Mark the submissionprocessing table each time through the loop
        // so that we do not become known as an "apparently stalled" processor.
        SetLockLastUpdatedTime($projectid);
        global $CDASH_SUBMISSION_PROCESSING_MAX_ATTEMPTS;
        if ($new_attempts > $CDASH_SUBMISSION_PROCESSING_MAX_ATTEMPTS) {
            add_log("Too many attempts to process '{$filename}'", 'ProcessSubmissions', LOG_ERR, $projectid);
            $new_status = 5;
            // done, called do_submit too many times already
        } else {
            // Record id in global so that we can mark it as "error status"
            // if we get thrown to the error handler.
            global $PHP_ERROR_SUBMISSION_ID;
            $PHP_ERROR_SUBMISSION_ID = $submission_id;
            if ($intentional_nonreturning_submit) {
                // simulate "error occurred" during do_submit:
                // status will be set to 4 in error handler.
                trigger_error('ProcessFile: intentional_nonreturning_submit is on', E_USER_ERROR);
            }
            $new_status = ProcessFile($projectid, $filename, $md5);
        }
        $PHP_ERROR_SUBMISSION_ID = 0;
        global $CDASH_ASYNC_EXPIRATION_TIME;
        if ($CDASH_ASYNC_EXPIRATION_TIME === 0 && ($new_status > 1 && $new_status < 6)) {
            // If our expiration time is set to 0 we delete finished
            // submissions rather than marking them as done in the database.
            pdo_query("DELETE FROM submission WHERE id='{$submission_id}'");
            add_last_sql_error('ProcessSubmissions-3');
            pdo_query("DELETE FROM submission2ip WHERE submissionid='{$submission_id}'");
            add_last_sql_error('ProcessSubmissions-3');
        } else {
            // Mark it as done with $new_status and record finished time:
            //
            $now_utc = gmdate(FMT_DATETIMESTD);
            pdo_query("UPDATE submission SET status={$new_status}, finished='{$now_utc}',\n                    lastupdated='{$now_utc}' WHERE id='{$submission_id}'");
            add_last_sql_error('ProcessSubmissions-3');
        }
        // Query for more... Continue processing while there are records to
        // process:
        //
        $query_array = GetNextSubmission($projectid);
        if ($query_array === false) {
            return false;
        }
        $n = count($query_array);
        $iterations = $iterations + 1;
    }
    return true;
}