Skip to content

Commit 3241c34

Browse files
avara1986alexppg
andauthored
Fix reload endpoint and Added docs to use this endpoint (#202)
Co-authored-by: Àlex Pérez <[email protected]>
1 parent 7ffce30 commit 3241c34

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

docs/configuration.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,29 @@ spec:
167167
```
168168

169169
See [Routing](routing.md) and [Examples](examples.md) to continue with this tutorial
170+
171+
## Reload configuration without stopping your services
172+
173+
In a production environment you may need to change the microservice's configuration without restarting it.
174+
175+
PyMS has a feature to reload the configuration:
176+
177+
```
178+
curl -X POST http://localhost:5000/reload-config
179+
```
180+
181+
This endpoint calls the method `Microservice.reload_conf()`, which restarts the services,
182+
the encryption configuration and initializes `create_app`.
183+
184+
```python
185+
def reload_conf(self):
186+
self.delete_services()
187+
self.config.reload()
188+
self.services = []
189+
self.init_services()
190+
self.crypt.config.reload()
191+
self.create_app()
192+
```
193+
194+
This means that your libraries will be restarted, which is why it's important to initialize your BD,
195+
your configuration inside `init_libs` method. See more info [how to use Microservice class in this link](ms_class.md)

pyms/utils/files.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,6 @@ def _get_conf_from_file(self, path, fn=None):
5656
return files_cached[path]
5757

5858
def reload(self, fn=None):
59-
files_cached.pop(self.path, None)
59+
path = self.path or self.get_path_from_env()
60+
files_cached.pop(path, None)
6061
return self.get_file(fn)

0 commit comments

Comments
 (0)