forked from github.com/blag
fixed devserver
so it does crash on build failure anymore. also made tests a bit faster by adding a wait parameter to the autoreload method.
This commit is contained in:
@@ -52,7 +52,7 @@ def get_last_modified(dirs: list[str]) -> float:
|
||||
return last_mtime
|
||||
|
||||
|
||||
def autoreload(args: argparse.Namespace) -> NoReturn:
|
||||
def autoreload(args: argparse.Namespace, wait: int=1) -> NoReturn:
|
||||
"""Start the autoreloader.
|
||||
|
||||
This method monitors the given directories for changes (i.e. the
|
||||
@@ -66,6 +66,9 @@ def autoreload(args: argparse.Namespace) -> NoReturn:
|
||||
----------
|
||||
args
|
||||
contains the input-, template- and static dir
|
||||
wait
|
||||
number of seconds the devsever waits before checking for updated
|
||||
content
|
||||
|
||||
"""
|
||||
dirs = [args.input_dir, args.template_dir, args.static_dir]
|
||||
@@ -74,12 +77,18 @@ def autoreload(args: argparse.Namespace) -> NoReturn:
|
||||
# loop to avoid serving stale contents
|
||||
last_mtime = 0.0
|
||||
while True:
|
||||
mtime = get_last_modified(dirs)
|
||||
if mtime > last_mtime:
|
||||
last_mtime = mtime
|
||||
logger.info("Change detected, rebuilding...")
|
||||
blag.build(args)
|
||||
time.sleep(1)
|
||||
# make sure the devsever does not crash when the build fails with an
|
||||
# exception
|
||||
try:
|
||||
mtime = get_last_modified(dirs)
|
||||
if mtime > last_mtime:
|
||||
last_mtime = mtime
|
||||
logger.info("Change detected, rebuilding...")
|
||||
blag.build(args)
|
||||
time.sleep(wait)
|
||||
except Exception:
|
||||
logger.exception("Error occurred during rebuild:")
|
||||
logger.info("Devserver did not crash, you may continue editing.")
|
||||
|
||||
|
||||
def serve(args: argparse.Namespace) -> None:
|
||||
|
||||
Reference in New Issue
Block a user