diff --git a/source/cartastraccia/actor.d b/source/cartastraccia/actor.d index 73b5106..1361c1b 100644 --- a/source/cartastraccia/actor.d +++ b/source/cartastraccia/actor.d @@ -158,7 +158,7 @@ /** * Resurrect a set of tasks by updating the associated data structs */ -TaskMap resurrect(RSSActorList feeds) +TaskMap resumeWorkers(RSSActorList feeds, TaskMap oldTasks) { TaskMap tasks; @@ -176,7 +176,14 @@ fl.each!( (RSSActor feed) { logInfo("Starting task: "~feed.name); - // start workers to serve RSS data + + // ensure all previous tasks are destroyed + if(oldTasks[feed.name].running()) { + logWarn("["~feed.name~"] Force stop."); + oldTasks[feed.name].interrupt(); + } + + // start new workers tasks[feed.name] = runWorkerTaskH( &feedActor, feed.name, feed.path, 0); }); diff --git a/source/cartastraccia/endpoint.d b/source/cartastraccia/endpoint.d index 941000b..81495d2 100644 --- a/source/cartastraccia/endpoint.d +++ b/source/cartastraccia/endpoint.d @@ -36,7 +36,7 @@ import vibe.web.web; import sumtype; -import std.algorithm : each; +import std.algorithm : each, filter; import std.datetime; import core.time; @@ -94,7 +94,7 @@ }); } - void getReload() + void getReload(scope HTTPServerRequest req, scope HTTPServerResponse res) { logInfo("Received reload request. Stopping current tasks."); @@ -120,7 +120,8 @@ feedList = feeds; }); - tasks = resurrect(feedList); + tasks = resumeWorkers(feedList, tasks); + res.writeBody("Successfully reloaded feeds file."); } @path("/") void getHTMLEndpoint(scope HTTPServerRequest req, scope HTTPServerResponse res) @@ -132,7 +133,8 @@ (RSSActor[] fl) { - fl.each!((RSSActor f) { + fl.filter!((RSSActor f) => f.name in tasks) + .each!((RSSActor f) { actorHandshake(f.name);