From: rich Date: Fri, 8 Dec 2006 14:10:37 +0000 (+0000) Subject: If fetching the RSS from the feed fails, keep using the old, cached X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=662d8a1f4bd09b346816295104daeb9673b3b280;p=cocanwiki.git If fetching the RSS from the feed fails, keep using the old, cached RSS (if it was in the cache). --- diff --git a/scripts/lib/cocanwiki_func_rss.ml b/scripts/lib/cocanwiki_func_rss.ml index dafeba7..b9d791c 100644 --- a/scripts/lib/cocanwiki_func_rss.ml +++ b/scripts/lib/cocanwiki_func_rss.ml @@ -1,5 +1,5 @@ (* An RSS feed reader function. - * $Id: cocanwiki_func_rss.ml,v 1.2 2006/12/07 17:16:17 rich Exp $ + * $Id: cocanwiki_func_rss.ml,v 1.3 2006/12/08 14:10:37 rich Exp $ *) open Printf @@ -197,15 +197,24 @@ let rss r dbh hostid arg = "select t, rss from rss_cache where url = $url" in let need_to_fetch, rss = match rows with - | [] -> true, "" (* not in cache, so have to fetch URL *) + | [] -> true, None (* not in cache, so have to fetch URL *) | (t, rss) :: _ -> if Calendar.compare (Calendar.add t refresh) (Calendar.now ()) < 0 then - true, "" + true, Some rss else - false, rss in + false, Some rss in if need_to_fetch then ( - let rss = fetch_url url in + (* If the fetch fails, keep using the old cached RSS. + * fetch_url prints the error in the error log in this case. + *) + let rss = + try fetch_url url + with Error _ as exn -> + match rss with + | Some rss -> rss + | None -> raise exn in + (* This lock is OK - refetches are supposed to be infrequent. *) PGSQL(dbh) "lock table rss_cache in share mode"; PGSQL(dbh) "delete from rss_cache where url = $url"; @@ -213,8 +222,11 @@ let rss r dbh hostid arg = PGOCaml.commit dbh; (* XXX How to avoid? *) PGOCaml.begin_work dbh; rss - ) else - rss in + ) else ( + match rss with + | Some rss -> rss + | None -> assert false + ) in (* Try to parse the RSS. *) let channel =