refactor: govern background job lifecycle
This commit is contained in:
@@ -32,17 +32,22 @@ def main() -> None:
|
||||
from server import RequestHandler, SERVICE
|
||||
|
||||
server = ThreadingHTTPServer(("127.0.0.1", args.port), RequestHandler)
|
||||
print(
|
||||
f"Preservation runtime is running at http://127.0.0.1:{args.port} "
|
||||
f"with database {SERVICE.database.path}",
|
||||
flush=True,
|
||||
)
|
||||
try:
|
||||
if hasattr(SERVICE, "start_background_jobs"):
|
||||
SERVICE.start_background_jobs()
|
||||
print(
|
||||
f"Preservation runtime is running at http://127.0.0.1:{args.port} "
|
||||
f"with database {SERVICE.database.path}",
|
||||
flush=True,
|
||||
)
|
||||
server.serve_forever()
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
finally:
|
||||
SERVICE._background_stop.set()
|
||||
if hasattr(SERVICE, "stop_background_jobs"):
|
||||
SERVICE.stop_background_jobs()
|
||||
else:
|
||||
SERVICE._background_stop.set()
|
||||
server.server_close()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user