Run workshop cron.
769292
public function execute() {
        global $CFG, $DB;

        $now = time();

        mtrace(' processing workshop subplugins ...');

        // Now when the scheduled allocator had a chance to do its job.
        // Check if there are some workshops to switch into the assessment phase.
        $workshops = $DB->get_records_select("workshop",
            "phase = 20 AND phaseswitchassessment = 1 AND submissionend > 0 AND submissionend < ?", [$now]);

        if (!empty($workshops)) {
            mtrace('Processing automatic assessment phase switch in ' . count($workshops) . ' workshop(s) ... ', '');
            require_once($CFG->dirroot . '/mod/workshop/locallib.php');
            foreach ($workshops as $workshop) {
                $cm = get_coursemodule_from_instance('workshop', $workshop->id, $workshop->course, false, MUST_EXIST);
                $course = $DB->get_record('course', ['id' => $cm->course], '*', MUST_EXIST);
                $workshop = new \workshop($workshop, $cm, $course);
                $workshop->switch_phase(workshop::PHASE_ASSESSMENT);

                $params = [
                    'objectid' => $workshop->id,
                    'context' => $workshop->context,
                    'courseid' => $workshop->course->id,
                    'other' => [
                        'workshopphase' => $workshop->phase
                    ]
                ];
                $event = \mod_workshop\event\phase_switched::create($params);
                $event->trigger();

                // Disable the automatic switching now so that it is not executed again by accident.
                // That can happen if the teacher changes the phase back to the submission one.
                $DB->set_field('workshop', 'phaseswitchassessment', 0, ['id' => $workshop->id]);
            }
            mtrace('done');
        }
    }
354971
protected function cron()
    {
        $this->addLogging();
        $this->fire();
        Cache::forever($this->HEARTBEAT_WORKER_KEY, time());
    }
1007631
def run(self):
        """"""
        event_handler = Handler()
        threads = []
        paths = [os.path.join(cwd, "content"), os.path.join(cwd, "templates")]

        for i in paths:
            targetPath = str(i)
            self.observer.schedule(event_handler, targetPath, recursive=True)
            threads.append(self.observer)

        self.observer.start()

        try:
            while True:
                time.sleep(5)
        except:
            self.observer.stop()
            print("\nObserver stopped.")

        self.observer.join()
1341799
public function execute() {
        global $CFG, $DB;

        $timenow = time();
        // Run the auth cron, if any before enrolments
        // because it might add users that will be needed in enrol plugins.
        $auths = get_enabled_auth_plugins();
        mtrace("Running auth crons if required...");
        foreach ($auths as $auth) {
            $authplugin = get_auth_plugin($auth);
            if (method_exists($authplugin, 'cron')) {
                mtrace("Running cron for auth/$auth...");
                $authplugin->cron();
                if (!empty($authplugin->log)) {
                    mtrace($authplugin->log);
                }
            }
            unset($authplugin);
        }

        // It is very important to run enrol early
        // because other plugins depend on correct enrolment info.
        mtrace("Running enrol crons if required...");
        $enrols = enrol_get_plugins(true);
        foreach ($enrols as $ename => $enrol) {
            // Do this for all plugins, disabled plugins might want to cleanup stuff such as roles.
            if (!$enrol->is_cron_required()) {
                continue;
            }
            mtrace("Running cron for enrol_$ename...");
            $enrol->cron();
            $enrol->set_config('lastcron', time());
        }

        // Run all cron jobs for each module.
        mtrace("Starting activity modules");
        if ($mods = $DB->get_records_select("modules", "cron > 0 AND ((? - lastcron) > cron) AND visible = 1", array($timenow))) {
            foreach ($mods as $mod) {
                $libfile = "$CFG->dirroot/mod/$mod->name/lib.php";
                if (file_exists($libfile)) {
                    include_once($libfile);
                    $cronfunction = $mod->name."_cron";
                    if (function_exists($cronfunction)) {
                        mtrace("Processing module function $cronfunction ...\n", '');
                        $predbqueries = null;
                        $predbqueries = $DB->perf_get_queries();
                        $pretime      = microtime(1);
                        if ($cronfunction()) {
                            $DB->set_field("modules", "lastcron", $timenow, array("id" => $mod->id));
                        }
                        if (isset($predbqueries)) {
                            mtrace("... used " . ($DB->perf_get_queries() - $predbqueries) . " dbqueries");
                            mtrace("... used " . (microtime(1) - $pretime) . " seconds");
                        }
                        // Reset possible changes by modules to time_limit. MDL-11597.
                        \core_php_time_limit::raise();
                        mtrace("done.");
                    }
                }
            }
        }
        mtrace("Finished activity modules");

        mtrace("Starting blocks");
        if ($blocks = $DB->get_records_select("block", "cron > 0 AND ((? - lastcron) > cron) AND visible = 1", array($timenow))) {
            // We will need the base class.
            require_once($CFG->dirroot.'/blocks/moodleblock.class.php');
            foreach ($blocks as $block) {
                $blockfile = $CFG->dirroot.'/blocks/'.$block->name.'/block_'.$block->name.'.php';
                if (file_exists($blockfile)) {
                    require_once($blockfile);
                    $classname = '\\block_'.$block->name;
                    $blockobj = new $classname;
                    if (method_exists($blockobj, 'cron')) {
                        mtrace("Processing cron function for ".$block->name.'....', '');
                        if ($blockobj->cron()) {
                            $DB->set_field('block', 'lastcron', $timenow, array('id' => $block->id));
                        }
                        // Reset possible changes by blocks to time_limit. MDL-11597.
                        \core_php_time_limit::raise();
                        mtrace('done.');
                    }
                }

            }
        }
        mtrace('Finished blocks');

        mtrace('Starting admin reports');
        cron_execute_plugin_type('report');
        mtrace('Finished admin reports');

        mtrace('Starting course reports');
        cron_execute_plugin_type('coursereport');
        mtrace('Finished course reports');

        // Run gradebook import/export/report cron.
        mtrace('Starting gradebook plugins');
        cron_execute_plugin_type('gradeimport');
        cron_execute_plugin_type('gradeexport');
        cron_execute_plugin_type('gradereport');
        mtrace('Finished gradebook plugins');

        // All other plugins.
        cron_execute_plugin_type('message', 'message plugins');
        cron_execute_plugin_type('filter', 'filters');
        cron_execute_plugin_type('editor', 'editors');
        cron_execute_plugin_type('format', 'course formats');
        cron_execute_plugin_type('profilefield', 'profile fields');
        cron_execute_plugin_type('webservice', 'webservices');
        cron_execute_plugin_type('repository', 'repository plugins');
        cron_execute_plugin_type('qbehaviour', 'question behaviours');
        cron_execute_plugin_type('qformat', 'question import/export formats');
        cron_execute_plugin_type('qtype', 'question types');
        cron_execute_plugin_type('plagiarism', 'plagiarism plugins');
        cron_execute_plugin_type('theme', 'themes');
        cron_execute_plugin_type('tool', 'admin tools');
        cron_execute_plugin_type('local', 'local plugins');
    }
653834
def StartRun(self, wait_for_start_event, signal_event, wait_for_write_event):
    """"""
    # Signal that the cron thread has started. This way the cron scheduler
    # will know that the task is not sitting in a threadpool queue, but is
    # actually executing.
    wait_for_start_event.set()
    # Wait until the cron scheduler acknowledges the run. If it doesn't
    # acknowledge, just return (it means that the cron scheduler considers
    # this task as "not started" and has returned the lease so that another
    # worker can pick it up).
    if not signal_event.wait(TASK_STARTUP_WAIT):
      return

    try:
      logging.info("Processing cron job: %s", self.job.cron_job_id)
      self.run_state.started_at = rdfvalue.RDFDatetime.Now()
      self.run_state.status = "RUNNING"

      data_store.REL_DB.WriteCronJobRun(self.run_state)
      data_store.REL_DB.UpdateCronJob(
          self.job.cron_job_id,
          last_run_time=rdfvalue.RDFDatetime.Now(),
          current_run_id=self.run_state.run_id,
          forced_run_requested=False)
    finally:
      # Notify the cron scheduler that all the DB updates are done. At this
      # point the cron scheduler can safely return this job's lease.
      wait_for_write_event.set()

    try:
      self.Run()
      self.run_state.status = "FINISHED"
    except LifetimeExceededError:
      self.run_state.status = "LIFETIME_EXCEEDED"
      stats_collector_instance.Get().IncrementCounter(
          "cron_job_failure", fields=[self.job.cron_job_id])
    except Exception as e:  # pylint: disable=broad-except
      logging.exception("Cronjob %s failed with an error: %s",
                        self.job.cron_job_id, e)
      stats_collector_instance.Get().IncrementCounter(
          "cron_job_failure", fields=[self.job.cron_job_id])
      self.run_state.status = "ERROR"
      self.run_state.backtrace = str(e)

    finally:
      self.run_state.finished_at = rdfvalue.RDFDatetime.Now()
      elapsed = self.run_state.finished_at - self.run_state.started_at
      stats_collector_instance.Get().RecordEvent(
          "cron_job_latency", elapsed.seconds, fields=[self.job.cron_job_id])
      if self.job.lifetime:
        expiration_time = self.run_state.started_at + self.job.lifetime
        if self.run_state.finished_at > expiration_time:
          self.run_state.status = "LIFETIME_EXCEEDED"
          stats_collector_instance.Get().IncrementCounter(
              "cron_job_timeout", fields=[self.job.cron_job_id])
      data_store.REL_DB.WriteCronJobRun(self.run_state)

    current_job = data_store.REL_DB.ReadCronJob(self.job.cron_job_id)
    # If no other job was started while we were running, update last status
    # information.
    if current_job.current_run_id == self.run_state.run_id:
      data_store.REL_DB.UpdateCronJob(
          self.job.cron_job_id,
          current_run_id=None,
          last_run_status=self.run_state.status)
671787
def run(self):
        """"""
        environment = os.environ.copy()
        # necessary for reading from processes that don't flush
        # stdout automatically
        environment["PYTHONUNBUFFERED"] = "1"
        self.proc = Popen(self.command, env=environment, stdout=PIPE, stderr=PIPE)
        Process.instances.append(self)
880451
def run(self):
        """"""
        while True:
            try:
                self.perform_iteration()
            except Exception:
                traceback.print_exc()
                pass

            time.sleep(ray_constants.REPORTER_UPDATE_INTERVAL_MS / 1000)
277480
def run_once(self):
        ''''''

        self._update_projects()
        self._check_task_done()
        self._check_request()
        while self._check_cronjob():
            pass
        self._check_select()
        self._check_delete()
        self._try_dump_cnt()
937399
public function executeCron()
    {
        $this->controlAccessExecuteCron();
        $this->cron->run();
        $this->response->outputHtml($this->text('Cron has started'));
    }
369508
def run(self):
        
        run_command = (
            settings.project_customization.runfile.read_text().split()
        )
        chmod_string = (
            "chmod +x "
            + settings.project_customization.runfile.absolute().as_posix()
        )
        subprocess.run(chmod_string.split())
        subprocess.run(
            run_command, stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr
        )
601537
public function runCron() {
        if (!Config::config()['user']['debug']['maintenance']) {
            $this->_controller();
            $this->_setHistory('CRON');
        }

        echo $this->response->page();
    }
1065408
def run(self, cmd):
        """"""
        print datetime.datetime.now()
        output = subprocess.Popen(cmd, shell=True)
        output = output.communicate()[0]
        print output
188865
def run(self):
        ''''''
        logger.info("scheduler starting...")

        while not self._quit:
            try:
                time.sleep(self.LOOP_INTERVAL)
                self.run_once()
                self._exceptions = 0
            except KeyboardInterrupt:
                break
            except Exception as e:
                logger.exception(e)
                self._exceptions += 1
                if self._exceptions > self.EXCEPTION_LIMIT:
                    break
                continue

        logger.info("scheduler exiting...")
        self._dump_cnt()
968830
def run_experiment(self):
        """"""
        try:
            self.sign_up()
            self.participate()
            if self.sign_off():
                self.complete_experiment("worker_complete")
            else:
                self.complete_experiment("worker_failed")
        finally:
            self.driver.quit()
1166708
def run(*args, **kwargs):
    '''
    
    '''
    lib = sys.modules[asynclib.lib_name]
    lib.run(*args, **kwargs)
427130
def scheduled(wait=False):
    """"""
    manager.run_scheduled()
    while wait:
        # Loop and try to run scheduled crawlers at short intervals
        manager.run_scheduled()
        time.sleep(settings.SCHEDULER_INTERVAL)
390670
public function start()
    {
        $this->logger->info("crontab start");
        $crontab = $this->createCrontab();
        $loop = Factory::create();

        // add periodic timer
        $loop->addPeriodicTimer(60, function () use ($crontab, $loop) {
            $loop->addTimer(60 - time() % 60, function () use ($crontab) {
                $pid = pcntl_fork();
                if ($pid > 0) {
                    return;
                } elseif ($pid == 0) {
                    $crontab->start(time());
                    exit();
                } else {
                    $this->logger->error("could not fork");
                }
            });
        });

        // recover the sub processes
        $loop->addPeriodicTimer(60, function () {
            while (($pid = pcntl_waitpid(0, $status, WNOHANG)) > 0) {
                $message = "process exit. pid:" . $pid . ". exit code:" . $status;
                $this->logger->info($message);
            }
        });

        $loop->run();
    }