diff --git a/README.md b/README.md index 90b98f4..94dc3b9 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,15 @@ where refresh time can be expressed in seconds `s`, minutes `m`, hours `h` or days `d`. You can see an example `feeds.conf` file included in the repository. +## How does it work + +Cartastraccia is composed by a daemon and a client. + +#### The Daemon + +The daemon when launched parses the feed configuration file (exiting on failure). +For every RSS feed a task (in the form of an actor) is launched + ## License This project is licensed under the terms of the GPLv3 License. diff --git a/source/cartastraccia/actor.d b/source/cartastraccia/actor.d index ef909b6..8932553 100644 --- a/source/cartastraccia/actor.d +++ b/source/cartastraccia/actor.d @@ -121,11 +121,11 @@ } /** - * Actor in charge of: - * - parsing a RSS feed - * - dumping news to DB - * - listening for messages from the webserver -*/ + * Requests and parse a RSS feed from a remote host. + * In case of success create an html page into: + * "public/channels/.html"; + * Function executed in a task. + */ void feedActor(immutable string feedName, immutable string path, immutable uint retries) @trusted { RSS rss; @@ -143,7 +143,7 @@ } catch (Exception e) { if(retries < ACTOR_MAX_RETRIES) { - feedActor(feedName, path, retries+1); + feedActor(feedName, path, retries+1); // retry by recurring return; } rss = FailedRSS(e.msg); diff --git a/source/cartastraccia/endpoint.d b/source/cartastraccia/endpoint.d index c4305ea..647d61a 100644 --- a/source/cartastraccia/endpoint.d +++ b/source/cartastraccia/endpoint.d @@ -46,6 +46,13 @@ html } +/** + * Implementing methods for a vibe Web Interface. + * Functions are mapped to a URL path via an attribute. + * + * For more informations see: + * vibed.org/api/vibe.web.web/registerWebInterface + */ class EndpointService { private { @@ -94,6 +101,10 @@ }); } + /** + * Called when an http request is made to ":/reload" + * Requests the rss feeds from their respective hosts. + */ void getReload(scope HTTPServerRequest req, scope HTTPServerResponse res) { logInfo("Received reload request. Stopping current tasks."); @@ -124,7 +135,11 @@ res.writeBody("Successfully reloaded feeds file."); } - @path("/") void getHTMLEndpoint(scope HTTPServerRequest req, scope HTTPServerResponse res) + /** + * Called when an http request is made to ":/". + * Returns the index file in html form. + */ + @path("/") void getHTMLEndpoint(scope HTTPServerRequest req, scope HTTPServerResponse res) { RSSActor[] validFeeds; feedList.match!( @@ -155,9 +170,10 @@ }); } - /** - * Debug purpose only ATM - */ + /** + * Called when an http request is made to ":/cli". + * Returns data gathered from the RSS feeds in a weakly formatted form. + */ @path("/cli") void getCLIEndpoint(scope HTTPServerResponse res) { string data; diff --git a/source/main.d b/source/main.d index a774942..e8b3a68 100644 --- a/source/main.d +++ b/source/main.d @@ -59,12 +59,17 @@ > echo \"Stallman 3h https://stallman.org/rss/rss.xml\" > feeds.conf -------------------------------------------------------------------------- 1. Start the daemon: -> cartastraccia --daemon --endpoint=cli --endpoint=html --feeds=feeds.conf +> cartastraccia --daemon --feeds=feeds.conf -------------------------------------------------------------------------- 2. Connect to daemon using HTML endpoint > cartastraccia --browser=/path/to/browser =========================================================================="; +/** + * Start a vibe.d webserver + * using an already initialied router + * Loops on the eventloop until stopped. + */ void runWebServer(ref URLRouter router, immutable string bindAddress, immutable ushort bindPort) { auto settings = new HTTPServerSettings; @@ -75,6 +80,13 @@ runEventLoop(); } +/** + * This function is in charge of: + * - reading `feeds.conf` + * - initializing an actor for each RSS feed, with early return in case of failure + * - registering a vibe.d router with an handle for each endpoint [html, cli, json, ...] + * - starting a webserver + */ void runDaemon(immutable string feedsFile, immutable string bindAddress, immutable ushort bindPort) {