-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for hot reloading the config.yaml
* add support for hot reloading the config.yaml * watchdogs also watches on example-config.yaml * watchdog remove os.system stuff * watchdog add requirments.{txt,in} --------- Co-authored-by: Andrew Nisbet <[email protected]>
- Loading branch information
1 parent
fc407a2
commit 9d51071
Showing
4 changed files
with
66 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import logging | ||
import time | ||
import warm_cache | ||
|
||
from watchdog.observers import Observer | ||
from watchdog.events import FileSystemEventHandler | ||
|
||
from pymemcache.client.base import Client | ||
|
||
|
||
#Connect to memcached socket. Since this is hardcoded in the supervisored.conf it shouldn't change that much | ||
memcacheClient = Client("/tmp/memcached.sock") | ||
|
||
|
||
def reload_config(): | ||
logging.error("config.yaml changes. Restarting uswgi and memcached to make the changes") | ||
#Restart uwsgi | ||
#TODO | ||
#Flush memcache using pymemcached | ||
memcacheClient.flush_all() | ||
warm_cache | ||
|
||
class Handler(FileSystemEventHandler): | ||
|
||
def on_created(self, event): | ||
reload_config() | ||
def on_modified(self, event): | ||
reload_config() | ||
|
||
|
||
|
||
|
||
|
||
CONFIG_PATH = "/app/config.yaml" | ||
EXAMPLE_CONFIG_PATH = "/app/example-config.yaml" | ||
|
||
if __name__ == "__main__": | ||
event_handler = Handler() | ||
observer = Observer() | ||
observer.schedule(event_handler, CONFIG_PATH) | ||
observer.schedule(event_handler, EXAMPLE_CONFIG_PATH) | ||
observer.start() | ||
try: | ||
while True: | ||
time.sleep(1) | ||
finally: | ||
observer.stop() | ||
observer.join() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters