{"action":"created","issue":{"url":"https://api.github.com/repos/IMA-WorldHealth/bhima/issues/554","labels_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/issues/554/labels{/name}","comments_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/issues/554/comments","events_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/issues/554/events","html_url":"https://github.com/IMA-WorldHealth/bhima/pull/554","id":88588435,"number":554,"title":"New plugin manager; complete mail plugin rewrite","user":{"login":"jniles","id":896472,"avatar_url":"https://avatars.githubusercontent.com/u/896472?v=3","gravatar_id":"","url":"https://api.github.com/users/jniles","html_url":"https://github.com/jniles","followers_url":"https://api.github.com/users/jniles/followers","following_url":"https://api.github.com/users/jniles/following{/other_user}","gists_url":"https://api.github.com/users/jniles/gists{/gist_id}","starred_url":"https://api.github.com/users/jniles/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jniles/subscriptions","organizations_url":"https://api.github.com/users/jniles/orgs","repos_url":"https://api.github.com/users/jniles/repos","events_url":"https://api.github.com/users/jniles/events{/privacy}","received_events_url":"https://api.github.com/users/jniles/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/IMA-WorldHealth/bhima/labels/enhancement","name":"enhancement","color":"84b6eb"},{"url":"https://api.github.com/repos/IMA-WorldHealth/bhima/labels/requires%20npm%20install","name":"requires npm install","color":"5319e7"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-06-16T01:52:30Z","updated_at":"2015-08-07T07:05:34Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/IMA-WorldHealth/bhima/pulls/554","html_url":"https://github.com/IMA-WorldHealth/bhima/pull/554","diff_url":"https://github.com/IMA-WorldHealth/bhima/pull/554.diff","patch_url":"https://github.com/IMA-WorldHealth/bhima/pull/554.patch"},"body":"This PR implements a new plugin manager (plugins/pluginManager.js).  It is fairly bare-bones at this point, but the structure is fully functional.  This PR is mostly for review by the team, with additions to be made in the future.\r\n\r\nEach plugin is loaded in a separate thread using `child_process.fork([plugin])`.  Configuration parameters are defined in `config/environment/server.js`.  Each plugin must define a schedule using a crontab syntax.   The schedule is parsed and interpreted using [laterjs](http://bunkat.github.io/later/).\r\n\r\nThe mail plugin has been completely rewritten as an example plugin.  Currently, the daily report has been implemented, but it should be very easy to create new reports by putting a folder in `mail/reports/{report_name}/` with `queries.json`, `{report_name}.tmpl.html`, and `{report_name}/lang/en.json` or `{report_name}/lang/fr.json` with appropriate translations.  Note: the French daily report is not yet translated.  For more information on how this works, see the README (`plugins/mail/README.md`).\r\n\r\nA nice bonus with the mail plugin is that templates are now defined using handlebarsjs-like syntax.  You can now write:\r\n```html\r\n<h1> {{ this.data.patientCount }} </h1>\r\n```\r\nand use a JSON object `{ data : { patientCount : 12 } }` to render the template with the correct values.  For database queries, specifying the locality (\"en\" or \"fr\") of the currency in the query will lead to automatic currency formatting in either Congolese Francs or USD.  The code for this is located inside `plugins/mail/lib/locales.js`.\r\n\r\nAny feedback would be appreciated.  There are still some bugs to be patched, but this is my proposal for the future of bhima plugins.  In the future, I'd like to move plugins into separate repositories, making them easier to maintain.  Any comments would be welcome."},"comment":{"url":"https://api.github.com/repos/IMA-WorldHealth/bhima/issues/comments/128618337","html_url":"https://github.com/IMA-WorldHealth/bhima/pull/554#issuecomment-128618337","issue_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/issues/554","id":128618337,"user":{"login":"jniles","id":896472,"avatar_url":"https://avatars.githubusercontent.com/u/896472?v=3","gravatar_id":"","url":"https://api.github.com/users/jniles","html_url":"https://github.com/jniles","followers_url":"https://api.github.com/users/jniles/followers","following_url":"https://api.github.com/users/jniles/following{/other_user}","gists_url":"https://api.github.com/users/jniles/gists{/gist_id}","starred_url":"https://api.github.com/users/jniles/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jniles/subscriptions","organizations_url":"https://api.github.com/users/jniles/orgs","repos_url":"https://api.github.com/users/jniles/repos","events_url":"https://api.github.com/users/jniles/events{/privacy}","received_events_url":"https://api.github.com/users/jniles/received_events","type":"User","site_admin":false},"created_at":"2015-08-07T07:05:34Z","updated_at":"2015-08-07T07:05:34Z","body":"One thing to note that I just realized:  If we ever plan on using [cluster](), two things have to be kept in mind: \r\n 1. The PluginManager should only be defined once, in the master node\r\n 2. We will have to figure out a new solution for HTTP requests made to plugins (the request might go to a child server that does not have access to the PluginManager.\r\n\r\nNaturally, we can cross these issues when we come to them, but it is important to realize that having a cluster of node servers will each spin up (or try to) a cluster of plugins."}}