1
0
mirror of https://github.com/venthur/blag.git synced 2025-11-26 05:02:58 +00:00

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:
Bastian Venthur
2024-04-24 21:47:59 +02:00
parent 4d4630867d
commit 0236dbf782
3 changed files with 53 additions and 18 deletions

View File

@@ -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: