|
| 1 | + |
| 2 | +# CEP-5: Care Apps |
| 3 | + |
| 4 | +## Requirements/Motive |
| 5 | + |
| 6 | +Since Care is being used in different environments for different use-cases, there must exist some method to efficiently create modifications which does not |
| 7 | +impact unrelated deployments. |
| 8 | + |
| 9 | +Some type of plugin system is required to achieve this. |
| 10 | + |
| 11 | +Plugins can be abstracted standalone features, they should be capable of being maintained as separate packages, this allows easy 3rd party integrations as well. |
| 12 | + |
| 13 | +Care must be modified to allow plugins to be easily created and configured. |
| 14 | + |
| 15 | +## Implementation |
| 16 | + |
| 17 | +To solve the problem in an abstracted way, a new package manager would be added onto care's core system. The core system |
| 18 | +will be responsible for maintaining the bare necessary components to operate a facility ( or a hospital ). Everything other |
| 19 | +than that can be made into apps that can be composed together to form deployments as required. |
| 20 | + |
| 21 | +A plugin will be called as a `plug` or an `app` ( `app` is already defined by django, so `plug` is used in those cases to avoid confusion ) |
| 22 | + |
| 23 | +Plugs will be managed in care through a plug manager and configured via a plug config, the plug config would take care of composing and defining plugs. |
| 24 | + |
| 25 | +Plugs will be added at build time rather than runtime, this allows care to be deployed in areas with no internet connectivity. At build time |
| 26 | +the plug manager would iterate through each plug and install it along with its requirements. plugs will also have hooks to be executed at this point. |
| 27 | + |
| 28 | +Plugs should not directly edit database structures maintained by the core system, plugs can have their own models and maintain relations if needed. |
| 29 | + |
| 30 | +Django signals can be used to listen for changes in the core system and react to them as needed. Custom signals can be created in the core system as needed |
| 31 | +to cater to the needs of the plugs. |
| 32 | + |
| 33 | +## Plug Config |
| 34 | + |
| 35 | +The plug config is located at the root of the project in the `plug_config.py` file. |
| 36 | + |
| 37 | +```python |
| 38 | + |
| 39 | +from plugs.manager import PlugManager |
| 40 | +from plugs.plug import Plug |
| 41 | + |
| 42 | +my_plugin = Plug( |
| 43 | + name="my_plugin", |
| 44 | + package_name="git+https://github.com/octo/my_plugin.git", |
| 45 | + version="@v1.0.0", |
| 46 | + configs={ |
| 47 | + "SERVICE_API_KEY": "my_api_key", |
| 48 | + "SERVICE_SECRET_KEY": "my_secret_key", |
| 49 | + "VALUE_1_MAX": 10, |
| 50 | + }, |
| 51 | +) |
| 52 | + |
| 53 | +plugs = [my_plugin] |
| 54 | + |
| 55 | +manager = PlugManager(plugs) |
| 56 | +``` |
| 57 | + |
| 58 | +The plugs variable is defined as a list of plugs, the developer can add plugins as needed here to compose a deployment. The configs dict |
| 59 | +can be used to override variables that the plug uses, this can also hold functions if needed to get fine grain control over the deployment. |
| 60 | + |
| 61 | + |
| 62 | +References: |
| 63 | +- https://github.com/openedx/edx-django-utils/tree/master/edx_django_utils/plugins |
| 64 | +- https://github.com/useblocks/groundwork |
0 commit comments