add DAEMON_UNSUCCESSFUL_DAYS_LIMIT tunable (defaults to 30 days)

This commit is contained in:
Andrew Dolgov 2020-09-30 17:03:16 +03:00
parent e641547d37
commit 8a02a728c8
2 changed files with 41 additions and 0 deletions

View File

@ -1582,6 +1582,43 @@ class RSSUtils {
$pdo->query("DELETE FROM ttrss_cat_counters_cache");
}
static function disable_failed_feeds() {
if (defined('DAEMON_UNSUCCESSFUL_DAYS_LIMIT') && DAEMON_UNSUCCESSFUL_DAYS_LIMIT > 0) {
$pdo = Db::pdo();
$pdo->beginTransaction();
$days = (int) DAEMON_UNSUCCESSFUL_DAYS_LIMIT;
if (DB_TYPE == "pgsql") {
$interval_query = "last_successful_update < NOW() - INTERVAL '$days days'";
} else if (DB_TYPE == "mysql") {
$interval_query = "last_successful_update < DATE_SUB(NOW(), INTERVAL $days DAY)";
}
$sth = $pdo->prepare("SELECT id, title, owner_uid
FROM ttrss_feeds
WHERE update_interval != -1 AND last_successful_update IS NOT NULL AND $interval_query");
$sth->execute();
while ($row = $sth->fetch()) {
Logger::get()->log(E_USER_NOTICE,
sprintf("Auto disabling feed %d (%s, UID: %d) because it failed to update for %d days.",
$row["id"], clean($row["title"]), $row["owner_uid"], DAEMON_UNSUCCESSFUL_DAYS_LIMIT));
Debug::log(sprintf("Auto-disabling feed %d (failed to update for %d days).", $row["id"], DAEMON_UNSUCCESSFUL_DAYS_LIMIT));
}
$sth = $pdo->prepare("UPDATE ttrss_feeds SET update_interval = -1 WHERE
update_interval != -1 AND last_successful_update IS NOT NULL AND $interval_query");
$sth->execute();
$pdo->commit();
}
}
static function housekeeping_user($owner_uid) {
$tmph = new PluginHost();
@ -1598,6 +1635,7 @@ class RSSUtils {
self::expire_feed_archive();
self::cleanup_feed_browser();
self::cleanup_feed_icons();
self::disable_failed_feeds();
Article::purge_orphans();
self::cleanup_counters_cache();

View File

@ -72,6 +72,9 @@
// this is used to not cause excessive load on the origin server on
// e.g. feed subscription when all articles are being processes
// (not implemented)
define_default('DAEMON_UNSUCCESSFUL_DAYS_LIMIT', 30);
// automatically disable updates for feeds which failed to
// update for this amount of days; 0 disables
/* tunables end here */