]> git.mjollnir.org Git - moodle.git/commitdiff
rss_client cron added. Min time between executions set to 5 mins. And
authorstronk7 <stronk7>
Tue, 31 Jul 2007 18:52:38 +0000 (18:52 +0000)
committerstronk7 <stronk7>
Tue, 31 Jul 2007 18:52:38 +0000 (18:52 +0000)
online fetching will use a double caching time, so chance of caching
feeds by the cron process will be near 100%. MDL-9292

blocks/rss_client/block_rss_client.php

index 3a24d5b054a814f210cdfeab6fbeb98a45f6410b..a62abf73c180e4f4ac749f4c470b563d754c01e5 100644 (file)
@@ -19,8 +19,8 @@
 
     function init() {
         $this->title = get_string('feedstitle', 'block_rss_client');
-        $this->version = 2007080100;
-        $this->cron = 1;
+        $this->version = 2007080101;
+        $this->cron = 300; /// Set min time between cron executions to 300 secs (5 mins)
     }
 
     function preferred_width() {
     function get_content() {
         global $CFG, $editing, $COURSE, $USER;
 
-        $starttime =  microtime();
-
         if (!empty($COURSE)) {
             $this->courseid = $COURSE->id;
         }
 
+    /// When displaying feeds in block, we double $CFG->block_rss_client_timeout
+    /// so those feeds retrieved and cached by the cron() process will have a
+    /// better chance to be used
+        if (!empty($CFG->block_rss_client_timeout)) {
+            $CFG->block_rss_client_timeout *= 2;
+        }
+
         require_once($CFG->libdir .'/rsslib.php');
 
         if($this->content !== NULL) {
         }
 
         $this->content->text = $output;
-        //echo 'Time: ' . microtime_diff($starttime, microtime());
         return $this->content;
     }
 
 
      // cron function, used to refresh all the RSS feeds from Moodle cron
      function cron() {
+
+         global $CFG;
+
+     /// We are going to measure execution times
+         $starttime =  microtime();
+
+     /// And we have one initial $status
+         $status = true;
+
+     /// We require some stuff
+         require_once($CFG->libdir .'/rsslib.php');
+         require_once(MAGPIE_DIR .'rss_fetch.inc');
+
+         if (!defined('MAGPIE_OUTPUT_ENCODING')) {
+             define('MAGPIE_OUTPUT_ENCODING', 'utf-8');  // see bug 3107
+         }
+
+     /// Fetch all site feeds.
          $rs = get_recordset('block_rss_client');
          $counter = 0;
+         mtrace('');
          while  ($rec = rs_fetch_next_record($rs)) {
+             mtrace('    ' . $rec->url . ' ', '');
+         /// Fetch the rss feed, using standard magpie caching
+         /// so feeds will be renewed only if cache has expired
+             if ($rss = fetch_rss($rec->url)) {
+                 mtrace ('ok');
+             } else {
+                 mtrace ('error');
+                 $status = false;
+             }
              $counter ++;
          }
          rs_close($rs);
-         mtrace($counter . ' feeds refreshed');
+
+     /// Show times
+         mtrace($counter . ' feeds refreshed (took ' . microtime_diff($starttime, microtime()) . ' seconds)');
+
+     /// And return $status
+         return $status;
      }
 }