diff --git a/source/cartastraccia/actor.d b/source/cartastraccia/actor.d index 407f70b..03123be 100644 --- a/source/cartastraccia/actor.d +++ b/source/cartastraccia/actor.d @@ -126,49 +126,57 @@ * "public/channels/.html"; * Function executed in a task. */ -void feedActor(immutable string feedName, immutable string path, immutable uint retries) @trusted nothrow +void feedActor(immutable string feedName, immutable string path) @trusted nothrow { - try { + uint retries = 0; + while(retries < ACTOR_MAX_RETRIES) { RSS rss; - URL url = URL(path); - auto req = Request(); - req.keepAlive = false; - req.timeout = ACTOR_REQ_TIMEOUT; - auto res = req.get(path); - string tmp = res.responseBody.data.assumeUTF; - validate(tmp); - if(tmp.empty) { - throw new Exception("Empty response from " ~ feedName ~ - ", removing from feeds."); - } - parseRSS(rss, tmp); - rss.match!( - (ref InvalidRSS i) { - logWarn("Invalid feed at: "~path); - logWarn("Caused by: \""~i.element~"\": "~i.content); - }, - (ref FailedRSS f) { - logWarn("Failed to load feed: "~ feedName); - logWarn("Error: "~f.msg); - }, - (ref ValidRSS vr) { - immutable fileName = "public/channels/"~feedName~".html"; - createHTMLPage(vr, feedName, fileName); - }); + try { + URL url = URL(path); + auto req = Request(); + req.keepAlive = false; + req.timeout = ACTOR_REQ_TIMEOUT; + auto res = req.get(path); + string tmp = res.responseBody.data.assumeUTF; + validate(tmp); + if(tmp.empty) { + throw new Exception("Empty response from " ~ feedName ~ + ", removing from feeds."); + } + parseRSS(rss, tmp); - listenOnce(feedName, rss); + rss.match!( + (ref InvalidRSS i) { + logWarn("Invalid feed at: "~path); + logWarn("Caused by: \""~i.element~"\": "~i.content); + }, + (ref FailedRSS f) { + logWarn("Failed to load feed: "~ feedName); + logWarn("Error: "~f.msg); + }, + (ref ValidRSS vr) { + immutable fileName = "public/channels/"~feedName~".html"; + createHTMLPage(vr, feedName, fileName); + }); - } catch (Exception e) { + } catch (Exception e) { - if(retries < ACTOR_MAX_RETRIES) { - feedActor(feedName, path, retries+1); // retry by recurring - return; - } - RSS frs = FailedRSS(e.msg); - listenOnce(feedName, frs); - } + if(retries >= ACTOR_MAX_RETRIES) { + rss = FailedRSS(e.msg); + } else { + continue; + } + } + // listenOnce is not nothrow + try { + listenOnce(feedName, rss); + } catch (Exception e) { + logWarn("Error listening for requests feed: " ~ feedName); + logWarn("Error: "~e.msg); + } + } } /**