diff --git a/source/app.d b/source/app.d index 23ff68f..d44fad8 100644 --- a/source/app.d +++ b/source/app.d @@ -77,10 +77,8 @@ (RSSFeed[] fl) { fl.each!( (RSSFeed feed) { - // start workers to serve RSS data - tasks[feed.name] = runWorkerTaskH(&feedActor, feed.name, feed.path); - + tasks[feed.name] = runTask(&feedActor, feed.name, feed.path); }); }); diff --git a/source/cartastraccia/config.d b/source/cartastraccia/config.d index 85134d2..e84ad3f 100644 --- a/source/cartastraccia/config.d +++ b/source/cartastraccia/config.d @@ -48,12 +48,10 @@ { string name; Duration refresh; - SysTime lastUpdate; string path; this(string[] props) @safe { - lastUpdate = Clock.currTime(); name = props[0]; path = props[3]; diff --git a/source/cartastraccia/endpoint.d b/source/cartastraccia/endpoint.d index f9fe282..196d428 100644 --- a/source/cartastraccia/endpoint.d +++ b/source/cartastraccia/endpoint.d @@ -30,18 +30,24 @@ TaskMap tasks; } + DateTime[string] lastUpdate; + this(RSSFeedList fl, TaskMap tm) { feedList = fl; tasks = tm; // refresh RSS data with a timer - feedList.tryMatch!((ref RSSFeed[] fl) { + feedList.tryMatch!((RSSFeed[] fl) { - fl.each!((ref RSSFeed feed) { + fl.each!((RSSFeed feed) { + + lastUpdate[feed.name] = cast(DateTime)Clock.currTime(); setTimer(feed.refresh, () { + logWarn("Updating: " ~ feed.name); + if(feed.name in tasks) tasks[feed.name].send(Task.getThis()); else return; @@ -52,10 +58,13 @@ return; } - tasks[feed.name].send(FeedActorRequest.QUIT); - tasks[feed.name] = runWorkerTaskH(&feedActor, feed.name, feed.path); + // set last update time + lastUpdate[feed.name] = cast(DateTime)Clock.currTime(); - feed.lastUpdate = Clock.currTime(); + tasks[feed.name].send(FeedActorRequest.QUIT); + tasks[feed.name] = runTask(&feedActor, feed.name, feed.path); + + logWarn("Finished updating: " ~ feed.name); }, true); }); @@ -95,7 +104,7 @@ }); feedList = validFeeds; - res.render!("index.dt", req, validFeeds, asciiArt); + res.render!("index.dt", req, validFeeds, lastUpdate, asciiArt); }); } diff --git a/views/index.dt b/views/index.dt index 6707d58..9beae21 100644 --- a/views/index.dt +++ b/views/index.dt @@ -12,24 +12,21 @@ - ulong flen = validFeeds.length; - foreach(feed; validFeeds[0..flen/2]) - import std.datetime; - - auto dt = cast(DateTime)feed.lastUpdate; - - immutable updated = dt.toSimpleString; + - immutable updated = lastUpdate[feed.name].toSimpleString; #chname1(class="index") h3 a(href="channels/"~feed.name~".html") #{feed.name} p a(href=feed.path) external link - b - Last update: #{updated} + b last update: #{updated} - foreach(feed; validFeeds[flen/2..$]) - import std.datetime; - - auto dt = cast(DateTime)feed.lastUpdate; - - immutable updated = dt.toSimpleString; + - immutable updated = lastUpdate[feed.name].toSimpleString; #chname2(class="index") h3 a(href="channels/"~feed.name~".html") #{feed.name} p a(href=feed.path) external link - b Last update: #{updated} + b last update: #{updated}