diff --git a/blocks/rss_client/block_rss_client.php b/blocks/rss_client/block_rss_client.php
index 4b861a84924186c3561f0dd8da7599f87d9bccd6..a30a73c7520bd419197f7b1236812c36220e9023 100644
--- a/blocks/rss_client/block_rss_client.php
+++ b/blocks/rss_client/block_rss_client.php
@@ -23,6 +23,9 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
*/
+define('BLOCK_RSS_CLIENT_MAX_SKIPTIME', 60*60*12); // SYNERGY LEARNING - Maximum time between trying failing RSS feeds.
+define('BLOCK_RSS_CLIENT_CRON_TIME', 300); // SYNERGY LEARNING - as this does not appear to get passed in to the cron function.
+
class block_rss_client extends block_base {
function init() {
@@ -292,6 +295,7 @@
// We are going to measure execution times
$starttime = microtime();
+ $starttimesec = time(); // SYNERGY LEARNING - added.
// And we have one initial $status
$status = true;
@@ -302,6 +306,14 @@
mtrace('');
foreach ($rs as $rec) {
mtrace(' ' . $rec->url . ' ', '');
+
+ // SYNERGY LEARNING - skip feed if it failed recently.
+ if ($starttimesec < $rec->skipuntil) {
+ mtrace('skipping until '.userdate($rec->skipuntil));
+ continue;
+ }
+ // SYNERGY LEARNING - skip feed if it failed recently.
+
// Fetch the rss feed, using standard simplepie caching
// so feeds will be renewed only if cache has expired
@set_time_limit(60);
@@ -315,11 +327,28 @@
$feed->init();
if ($feed->error()) {
- mtrace ('error');
- mtrace ('SimplePie failed with error:'.$feed->error());
- $status = false;
+ //$status = false; // SYNERGY LEARNING - do not return an error if feed fails (as that causes this script to run EVERY cron update).
+ // SYNERGY LEARNING - skip this feed (for an ever-increasing time if it keeps failing).
+ if ($rec->skiptime == 0) { // Not failed recently
+ $rec->skiptime = BLOCK_RSS_CLIENT_CRON_TIME * 1.1; // Make sure we skip the next cron update.
+ } else {
+ $rec->skiptime *= 2; // Double the last time.
+ if ($rec->skiptime > BLOCK_RSS_CLIENT_MAX_SKIPTIME) {
+ $rec->skiptime = BLOCK_RSS_CLIENT_MAX_SKIPTIME;
+ }
+ }
+ $rec->skipuntil = time() + $rec->skiptime;
+ $DB->update_record('block_rss_client', $rec);
+ mtrace("SimplePie error - skipping for {$rec->skiptime} seconds:".$feed->error());
+ // SYNERGY LEARNING - skip this feed (for an ever-increasing time if it keeps failing).
} else {
mtrace ('ok');
+ // SYNERGY LEARNING - it worked this time, so reset the skiptime.
+ if ($rec->skiptime > 0) {
+ $rec->skiptime = 0;
+ $DB->update_record('block_rss_client', $rec);
+ }
+ // SYNERGY LEARNING - it worked this time, so reset the skiptime.
}
$counter ++;
}
diff --git a/blocks/rss_client/db/install.xml b/blocks/rss_client/db/install.xml
index f81d650cf62307b0c9491c5ec292acdfcefe5fb4..d4e5c513f4c1d403b84c33e1884f73b206f16ad9 100644
--- a/blocks/rss_client/db/install.xml
+++ b/blocks/rss_client/db/install.xml
@@ -13,6 +13,8 @@
+
+
diff --git a/blocks/rss_client/db/upgrade.php b/blocks/rss_client/db/upgrade.php
new file mode 100644
index 0000000000000000000000000000000000000000..1067c5764ff63845521f54fafcd9cedfbc1141e4
--- /dev/null
+++ b/blocks/rss_client/db/upgrade.php
@@ -0,0 +1,31 @@
+get_manager();
+
+ // SYNERGY LEARNING - support for skipping RSS feeds for a while when they fail.
+ if ($oldversion < 2012010302) {
+ $table = new xmldb_table('block_rss_client');
+
+ // How many seconds we are currently ignoring this RSS feed for (due to an error)
+ $field = new xmldb_field('skiptime', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'url');
+ if (!$dbman->field_exists($table, $field)) {
+ $dbman->add_field($table, $field);
+ }
+
+ // When to next update this RSS feed
+ $field = new xmldb_field('skipuntil', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'skiptime');
+ if (!$dbman->field_exists($table, $field)) {
+ $dbman->add_field($table, $field);
+ }
+
+ upgrade_block_savepoint(true, 2012010302, 'rss_client');
+ }
+ // SYNERGY LEARNING - support for skipping RSS feeds for a while when they fail.
+
+ return true;
+}
\ No newline at end of file