Check to see if wp-cron event is overdue by 24 hours and report error message.

@param array $cron
@param int   $timestamp
482030
public function is_cron_overdue( $cron, $timestamp ) {
		$overdue = ( ( time() - $timestamp ) / HOUR_IN_SECONDS ) > 24;
		if ( $overdue ) {
			$error_msg = esc_html__( 'There may be a problem with WP-Cron. A GitHub Updater WP-Cron event is overdue.', 'github-updater' );
			$error     = new \WP_Error( 'github_updater_cron_error', $error_msg );
			Singleton::get_instance( 'Messages', $this )->create_error_message( $error );
		}
	}
337268
protected function isLocked(Cron $cron)
    {
        $hourAgo = new \DateTime('-65 minutes');
        if ($cron->getState() === Cron::STATE_RUNNING && $cron->getStartedAt() > $hourAgo) {
            return true;
        }

        return false;
    }
337439
function setTimeStamp( $timestamp )
    {
        $date = getdate( $timestamp );
        $this->Time = $date[ 'hours' ] * self::SECONDS_AN_HOUR +
                      $date[ 'minutes' ] * self::SECONDS_A_MINUTE +
                      $date[ 'seconds' ];
    }
1009992
protected function setCron()
    {
        $interval = (int) $this->config('cron_interval', 24 * 60 * 60);

        if (!empty($interval) && (GC_TIME - $this->config('cron_last_run', 0)) > $interval) {
            $url = $this->url('cron', array('key' => $this->config('cron_key', '')));
            $this->setJs("\$(function(){\$.get('$url', function(data){});});", array('position' => 'bottom'));
        }
    }
153106
private static function validateTimestamp($timestamp) {

        $check = (is_int($timestamp) || is_float($timestamp))
            ? $timestamp
            : (string) (int) $timestamp;

        return  ($check === $timestamp)
            AND ( (int) $timestamp <=  PHP_INT_MAX)
            AND ( (int) $timestamp >= ~PHP_INT_MAX);
    }
1115609
public function cmdCronCron()
    {
        if (!$this->cron->run()) {
            $this->errorAndExit($this->text('Unexpected result'));
        }

        $this->output();
    }
105382
public function isTimeIncluded($timeStamp)
    {
        // Test the base calendar first. Only if the base calendar not already
        // excludes the time/date, continue evaluating this calendar instance.
        if (false == parent::isTimeIncluded($timeStamp)) {
            return false;
        }

        $date = $this->createDateTime($timeStamp);
        $day = (int) $date->format('j');

        return false == $this->isDayExcluded($day);
    }
554725
private function isModified($timestamp)
    {
        $target = 'If-Modified-Since';

        if ($this->headerBag->hasRequestHeader($target)) {
            $sinceTimestamp = strtotime($this->headerBag->getRequestHeader($target));

            if ($sinceTimestamp != false && $timestamp <= $sinceTimestamp) {
                return false;
            }
        }

        // By default
        return true;
    }
31909
public function isVisitTime($timestamp = null)
    {
        $timestamp = is_int($timestamp) ? $timestamp : time();
        foreach ($this->times as $time) {
            if ($this->isBetween($timestamp, $time['from'], $time['to'], 'Hi')) {
                return true;
            }
        }
        return empty($this->times);
    }
1905
protected function cron_has_fresh_fetch($now) {
        $recent = $this->get_last_timefetched();

        if (empty($recent)) {
            return false;
        }

        if ($now < $recent) {
            $this->cron_mtrace('The most recent fetch is reported to be in the future, this is weird!');
            return true;
        }

        if ($now - $recent > 24 * HOURSECS) {
            return false;
        }

        return true;
    }
1173182
public static function cron() {
        global $DB;

        // Only ever send a max of one days worth of updates.
        $yesterday = time() - (24 * 3600);
        $timenow   = time();
        $lastcron = $DB->get_field('modules', 'lastcron', array('name' => 'assign'));

        // Collect all submissions that require mailing.
        // Submissions are included if all are true:
        //   - The assignment is visible in the gradebook.
        //   - No previous notification has been sent.
        //   - The grader was a real user, not an automated process.
        //   - If marking workflow is not enabled, the grade was updated in the past 24 hours, or
        //     if marking workflow is enabled, the workflow state is at 'released'.
        $sql = "SELECT g.id as gradeid, a.course, a.name, a.blindmarking, a.revealidentities, a.hidegrader,
                       g.*, g.timemodified as lastmodified, cm.id as cmid, um.id as recordid
                 FROM {assign} a
                 JOIN {assign_grades} g ON g.assignment = a.id
            LEFT JOIN {assign_user_flags} uf ON uf.assignment = a.id AND uf.userid = g.userid
                 JOIN {course_modules} cm ON cm.course = a.course AND cm.instance = a.id
                 JOIN {modules} md ON md.id = cm.module AND md.name = 'assign'
                 JOIN {grade_items} gri ON gri.iteminstance = a.id AND gri.courseid = a.course AND gri.itemmodule = md.name
            LEFT JOIN {assign_user_mapping} um ON g.id = um.userid AND um.assignment = a.id
                 WHERE ((a.markingworkflow = 0 AND g.timemodified >= :yesterday AND g.timemodified <= :today) OR
                        (a.markingworkflow = 1 AND uf.workflowstate = :wfreleased)) AND
                       g.grader > 0 AND uf.mailed = 0 AND gri.hidden = 0
              ORDER BY a.course, cm.id";

        $params = array(
            'yesterday' => $yesterday,
            'today' => $timenow,
            'wfreleased' => ASSIGN_MARKING_WORKFLOW_STATE_RELEASED,
        );
        $submissions = $DB->get_records_sql($sql, $params);

        if (!empty($submissions)) {

            mtrace('Processing ' . count($submissions) . ' assignment submissions ...');

            // Preload courses we are going to need those.
            $courseids = array();
            foreach ($submissions as $submission) {
                $courseids[] = $submission->course;
            }

            // Filter out duplicates.
            $courseids = array_unique($courseids);
            $ctxselect = context_helper::get_preload_record_columns_sql('ctx');
            list($courseidsql, $params) = $DB->get_in_or_equal($courseids, SQL_PARAMS_NAMED);
            $sql = 'SELECT c.*, ' . $ctxselect .
                      ' FROM {course} c
                 LEFT JOIN {context} ctx ON ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel
                     WHERE c.id ' . $courseidsql;

            $params['contextlevel'] = CONTEXT_COURSE;
            $courses = $DB->get_records_sql($sql, $params);

            // Clean up... this could go on for a while.
            unset($courseids);
            unset($ctxselect);
            unset($courseidsql);
            unset($params);

            // Message students about new feedback.
            foreach ($submissions as $submission) {

                mtrace("Processing assignment submission $submission->id ...");

                // Do not cache user lookups - could be too many.
                if (!$user = $DB->get_record('user', array('id'=>$submission->userid))) {
                    mtrace('Could not find user ' . $submission->userid);
                    continue;
                }

                // Use a cache to prevent the same DB queries happening over and over.
                if (!array_key_exists($submission->course, $courses)) {
                    mtrace('Could not find course ' . $submission->course);
                    continue;
                }
                $course = $courses[$submission->course];
                if (isset($course->ctxid)) {
                    // Context has not yet been preloaded. Do so now.
                    context_helper::preload_from_record($course);
                }

                // Override the language and timezone of the "current" user, so that
                // mail is customised for the receiver.
                cron_setup_user($user, $course);

                // Context lookups are already cached.
                $coursecontext = context_course::instance($course->id);
                if (!is_enrolled($coursecontext, $user->id)) {
                    $courseshortname = format_string($course->shortname,
                                                     true,
                                                     array('context' => $coursecontext));
                    mtrace(fullname($user) . ' not an active participant in ' . $courseshortname);
                    continue;
                }

                if (!$grader = $DB->get_record('user', array('id'=>$submission->grader))) {
                    mtrace('Could not find grader ' . $submission->grader);
                    continue;
                }

                $modinfo = get_fast_modinfo($course, $user->id);
                $cm = $modinfo->get_cm($submission->cmid);
                // Context lookups are already cached.
                $contextmodule = context_module::instance($cm->id);

                if (!$cm->uservisible) {
                    // Hold mail notification for assignments the user cannot access until later.
                    continue;
                }

                // Notify the student. Default to the non-anon version.
                $messagetype = 'feedbackavailable';
                // Message type needs 'anon' if "hidden grading" is enabled and the student
                // doesn't have permission to see the grader.
                if ($submission->hidegrader && !has_capability('mod/assign:showhiddengrader', $contextmodule, $user)) {
                    $messagetype = 'feedbackavailableanon';
                    // There's no point in having an "anonymous grader" if the notification email
                    // comes from them. Send the email from the noreply user instead.
                    $grader = core_user::get_noreply_user();
                }

                $eventtype = 'assign_notification';
                $updatetime = $submission->lastmodified;
                $modulename = get_string('modulename', 'assign');

                $uniqueid = 0;
                if ($submission->blindmarking && !$submission->revealidentities) {
                    if (empty($submission->recordid)) {
                        $uniqueid = self::get_uniqueid_for_user_static($submission->assignment, $grader->id);
                    } else {
                        $uniqueid = $submission->recordid;
                    }
                }
                $showusers = $submission->blindmarking && !$submission->revealidentities;
                self::send_assignment_notification($grader,
                                                   $user,
                                                   $messagetype,
                                                   $eventtype,
                                                   $updatetime,
                                                   $cm,
                                                   $contextmodule,
                                                   $course,
                                                   $modulename,
                                                   $submission->name,
                                                   $showusers,
                                                   $uniqueid);

                $flags = $DB->get_record('assign_user_flags', array('userid'=>$user->id, 'assignment'=>$submission->assignment));
                if ($flags) {
                    $flags->mailed = 1;
                    $DB->update_record('assign_user_flags', $flags);
                } else {
                    $flags = new stdClass();
                    $flags->userid = $user->id;
                    $flags->assignment = $submission->assignment;
                    $flags->mailed = 1;
                    $DB->insert_record('assign_user_flags', $flags);
                }

                mtrace('Done');
            }
            mtrace('Done processing ' . count($submissions) . ' assignment submissions');

            cron_setup_user();

            // Free up memory just to be sure.
            unset($courses);
        }

        // Update calendar events to provide a description.
        $sql = 'SELECT id
                    FROM {assign}
                    WHERE
                        allowsubmissionsfromdate >= :lastcron AND
                        allowsubmissionsfromdate <= :timenow AND
                        alwaysshowdescription = 0';
        $params = array('lastcron' => $lastcron, 'timenow' => $timenow);
        $newlyavailable = $DB->get_records_sql($sql, $params);
        foreach ($newlyavailable as $record) {
            $cm = get_coursemodule_from_instance('assign', $record->id, 0, false, MUST_EXIST);
            $context = context_module::instance($cm->id);

            $assignment = new assign($context, null, null);
            $assignment->update_calendar($cm->id);
        }

        return true;
    }
331660
public static function update_cron() {
        global $DB;

        if (!$registration = self::get_registration()) {
            mtrace(get_string('registrationwarning', 'admin'));
            return;
        }

        if (self::get_new_registration_fields()) {
            mtrace(get_string('pleaserefreshregistrationnewdata', 'admin'));
            return;
        }

        $siteinfo = self::get_site_info();
        api::update_registration($siteinfo);
        $DB->update_record('registration_hubs', ['id' => $registration->id, 'timemodified' => time()]);
        mtrace(get_string('siteregistrationupdated', 'hub'));
        self::$registration = null;
    }
950704
protected function configureEvent($event, array $definition)
    {
        if (isset($definition['cron'])) {
            $event->cron($definition['cron']);
        }

        if (isset($definition['singleton']) && $definition['singleton']) {
            $event->onOneServer();
        }

        if (isset($definition['mutex']) && $definition['mutex']) {
            $event->withoutOverlapping();
        }
    }
853167
def remove_cron(self, client, event):
        """"""
        for index, cron in enumerate(self.crons):
            if cron.event == event:
                _log.info("De-registering cron '%s'.", event)
                # Yes, we're modifying the list we're iterating over, but
                # we immediate stop iterating so it's okay.
                self.crons.pop(index)
                break
        return True
281573
public function expireAt($key, $timestamp) {
        return $this->getHandler($this->judge(__FUNCTION__))->expireAt($key, $timestamp);
    }
588006
private function changeState(Cron $cron, $state, $lastError = null)
    {
        $cron->setState($state);
        $cron->setLastError($lastError);

        $em = $this->getEntityManager();
        $em->persist($cron);
        $em->flush($cron);
    }
1084148
protected function setExpiresAtFromTimeStamp($timeStamp)
    {
        $dt = new \DateTime();
        $dt->setTimestamp($timeStamp);
        $this->expiresAt = $dt;
    }