original_string: public function execute() {
          global $CFG, $DB;
          require_once("{$CFG->libdir}/simplepie/moodle_simplepie.php");
  
          // We are going to measure execution times.
          $starttime = microtime();
          $starttimesec = time();
  
          // Fetch all site feeds.
          $rs = $DB->get_recordset('block_rss_client');
          $counter = 0;
          mtrace('');
          foreach ($rs as $rec) {
              mtrace('    ' . $rec->url . ' ', '');
  
              // Skip feed if it failed recently.
              if ($starttimesec < $rec->skipuntil) {
                  mtrace('skipping until ' . userdate($rec->skipuntil));
                  continue;
              }
  
              $feed = $this->fetch_feed($rec->url);
  
              if ($feed->error()) {
                  // Skip this feed (for an ever-increasing time if it keeps failing).
                  $rec->skiptime = $this->calculate_skiptime($rec->skiptime);
                  $rec->skipuntil = time() + $rec->skiptime;
                  $DB->update_record('block_rss_client', $rec);
                  mtrace("Error: could not load/find the RSS feed - skipping for {$rec->skiptime} seconds.");
              } else {
                  mtrace ('ok');
                  // It worked this time, so reset the skiptime.
                  if ($rec->skiptime > 0) {
                      $rec->skiptime = 0;
                      $rec->skipuntil = 0;
                      $DB->update_record('block_rss_client', $rec);
                  }
                  // Only increase the counter when a feed is sucesfully refreshed.
                  $counter ++;
              }
          }
          $rs->close();
  
          // Show times.
          mtrace($counter . ' feeds refreshed (took ' . microtime_diff($starttime, microtime()) . ' seconds)');
      }
code: public function execute() {
          global $CFG, $DB;
          require_once("{$CFG->libdir}/simplepie/moodle_simplepie.php");
  
          // We are going to measure execution times.
          $starttime = microtime();
          $starttimesec = time();
  
          // Fetch all site feeds.
          $rs = $DB->get_recordset('block_rss_client');
          $counter = 0;
          mtrace('');
          foreach ($rs as $rec) {
              mtrace('    ' . $rec->url . ' ', '');
  
              // Skip feed if it failed recently.
              if ($starttimesec < $rec->skipuntil) {
                  mtrace('skipping until ' . userdate($rec->skipuntil));
                  continue;
              }
  
              $feed = $this->fetch_feed($rec->url);
  
              if ($feed->error()) {
                  // Skip this feed (for an ever-increasing time if it keeps failing).
                  $rec->skiptime = $this->calculate_skiptime($rec->skiptime);
                  $rec->skipuntil = time() + $rec->skiptime;
                  $DB->update_record('block_rss_client', $rec);
                  mtrace("Error: could not load/find the RSS feed - skipping for {$rec->skiptime} seconds.");
              } else {
                  mtrace ('ok');
                  // It worked this time, so reset the skiptime.
                  if ($rec->skiptime > 0) {
                      $rec->skiptime = 0;
                      $rec->skipuntil = 0;
                      $DB->update_record('block_rss_client', $rec);
                  }
                  // Only increase the counter when a feed is sucesfully refreshed.
                  $counter ++;
              }
          }
          $rs->close();
  
          // Show times.
          mtrace($counter . ' feeds refreshed (took ' . microtime_diff($starttime, microtime()) . ' seconds)');
      }
code_tokens: public function execute ( ) { global $ CFG , $ DB ; require_once ( "{$CFG->libdir}/simplepie/moodle_simplepie.php" ) ; // We are going to measure execution times. $ starttime = microtime ( ) ; $ starttimesec = time ( ) ; // Fetch all site feeds. $ rs = $ DB -> get_recordset ( 'block_rss_client' ) ; $ counter = 0 ; mtrace ( '' ) ; foreach ( $ rs as $ rec ) { mtrace ( '    ' . $ rec -> url . ' ' , '' ) ; // Skip feed if it failed recently. if ( $ starttimesec < $ rec -> skipuntil ) { mtrace ( 'skipping until ' . userdate ( $ rec -> skipuntil ) ) ; continue ; } $ feed = $ this -> fetch_feed ( $ rec -> url ) ; if ( $ feed -> error ( ) ) { // Skip this feed (for an ever-increasing time if it keeps failing). $ rec -> skiptime = $ this -> calculate_skiptime ( $ rec -> skiptime ) ; $ rec -> skipuntil = time ( ) + $ rec -> skiptime ; $ DB -> update_record ( 'block_rss_client' , $ rec ) ; mtrace ( "Error: could not load/find the RSS feed - skipping for {$rec->skiptime} seconds." ) ; } else { mtrace ( 'ok' ) ; // It worked this time, so reset the skiptime. if ( $ rec -> skiptime > 0 ) { $ rec -> skiptime = 0 ; $ rec -> skipuntil = 0 ; $ DB -> update_record ( 'block_rss_client' , $ rec ) ; } // Only increase the counter when a feed is sucesfully refreshed. $ counter ++ ; } } $ rs -> close ( ) ; // Show times. mtrace ( $ counter . ' feeds refreshed (took ' . microtime_diff ( $ starttime , microtime ( ) ) . ' seconds)' ) ; }
docstring: This task goes through all the feeds. If the feed has a skipuntil value
  that is less than the current time cron will attempt to retrieve it
  with the cache duration set to 0 in order to force the retrieval of
  the item and refresh the cache.
  
  If a feed fails then the skipuntil time of that feed is set to be
  later than the next expected task time. The amount of time will
  increase each time the fetch fails until the maximum is reached.
  
  If a feed that has been failing is successfully retrieved it will
  go back to being handled as though it had never failed.
  
  Task should therefore process requests for permanently broken RSS
  feeds infrequently, and temporarily unavailable feeds will be tried
  less often until they become available again.
docstring_tokens: This task goes through all the feeds . If the feed has a skipuntil value that is less than the current time cron will attempt to retrieve it with the cache duration set to 0 in order to force the retrieval of the item and refresh the cache .