refactorig of webserver startup logic
This commit is contained in:
parent
daaa0ed958
commit
2ad7fc6477
@ -24,11 +24,12 @@ minio:
|
|||||||
bucket: $STORAGE_BUCKET_NAME|redaction # MinIO bucket
|
bucket: $STORAGE_BUCKET_NAME|redaction # MinIO bucket
|
||||||
|
|
||||||
service:
|
service:
|
||||||
logging_level: $LOGGING_LEVEL_ROOT|DEBUG # Logging level for log file messages
|
logging_level: $LOGGING_LEVEL_ROOT|DEBUG # Logging level for service logger
|
||||||
name: $SERVICE_NAME|pyinfra-service-v1 # Name of the service in the kubernetes cluster
|
name: $SERVICE_NAME|pyinfra-service-v1 # Name of the service in the kubernetes cluster
|
||||||
storage_backend: $STORAGE_BACKEND|s3 # The storage to pull files to be processed from
|
storage_backend: $STORAGE_BACKEND|s3 # The storage to pull files to be processed from
|
||||||
analysis_endpoint: $ANALYSIS_ENDPOINT|"http://127.0.0.1:5000"
|
analysis_endpoint: $ANALYSIS_ENDPOINT|"http://127.0.0.1:5000"
|
||||||
|
|
||||||
webserver:
|
probing_webserver:
|
||||||
host: $PROBE_SERVER_HOST|"0.0.0.0" # Probe webserver address
|
host: $PROBING_WEBSERVER_HOST|"0.0.0.0" # Probe webserver address
|
||||||
port: $PROBE_SERVER_PORT|8080 # Probe webserver port
|
port: $PROBING_WEBSERVER_PORT|8080 # Probe webserver port
|
||||||
|
mode: "development"
|
||||||
|
|||||||
41
pyinfra/flask.py
Normal file
41
pyinfra/flask.py
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
from flask import Flask, jsonify
|
||||||
|
from waitress import serve
|
||||||
|
|
||||||
|
from pyinfra.config import CONFIG
|
||||||
|
|
||||||
|
|
||||||
|
def run_probing_webserver(app, host=None, port=None, mode=None):
|
||||||
|
|
||||||
|
if not host:
|
||||||
|
host = CONFIG.probing_webserver.host
|
||||||
|
|
||||||
|
if not port:
|
||||||
|
port = CONFIG.probing_webserver.port
|
||||||
|
|
||||||
|
if not mode:
|
||||||
|
mode = CONFIG.probing_webserver.port
|
||||||
|
|
||||||
|
if mode == "development":
|
||||||
|
app.run(host=host, port=port, debug=True)
|
||||||
|
|
||||||
|
elif mode == "production":
|
||||||
|
serve(app, host=host, port=port)
|
||||||
|
|
||||||
|
|
||||||
|
def set_up_probing_webserver():
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
@app.route("/ready", methods=["GET"])
|
||||||
|
def ready():
|
||||||
|
resp = jsonify("OK")
|
||||||
|
resp.status_code = 200
|
||||||
|
return resp
|
||||||
|
|
||||||
|
@app.route("/health", methods=["GET"])
|
||||||
|
def healthy():
|
||||||
|
resp = jsonify("OK")
|
||||||
|
resp.status_code = 200
|
||||||
|
return resp
|
||||||
|
|
||||||
|
return app
|
||||||
26
src/serve.py
26
src/serve.py
@ -2,8 +2,6 @@ import logging
|
|||||||
from multiprocessing import Process
|
from multiprocessing import Process
|
||||||
|
|
||||||
import pika
|
import pika
|
||||||
from flask import Flask, jsonify
|
|
||||||
from waitress import serve
|
|
||||||
|
|
||||||
from pyinfra.callback import (
|
from pyinfra.callback import (
|
||||||
make_retry_callback_for_output_queue,
|
make_retry_callback_for_output_queue,
|
||||||
@ -14,31 +12,12 @@ from pyinfra.config import CONFIG
|
|||||||
from pyinfra.consume import consume, ConsumerError
|
from pyinfra.consume import consume, ConsumerError
|
||||||
from pyinfra.core import make_payload_processor, make_storage_data_loader, make_analyzer
|
from pyinfra.core import make_payload_processor, make_storage_data_loader, make_analyzer
|
||||||
from pyinfra.exceptions import UnknownStorageBackend
|
from pyinfra.exceptions import UnknownStorageBackend
|
||||||
|
from pyinfra.flask import run_probing_webserver, set_up_probing_webserver
|
||||||
from pyinfra.storage.azure_blob_storage import AzureBlobStorageHandle
|
from pyinfra.storage.azure_blob_storage import AzureBlobStorageHandle
|
||||||
from pyinfra.storage.minio import MinioHandle
|
from pyinfra.storage.minio import MinioHandle
|
||||||
|
|
||||||
|
|
||||||
# TODO: implement meaningful checks
|
# TODO: implement meaningful checks
|
||||||
def start_integrity_checks_webserver(mode="debug"):
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
|
||||||
|
|
||||||
@app.route("/ready", methods=["GET"])
|
|
||||||
def ready():
|
|
||||||
resp = jsonify("OK")
|
|
||||||
resp.status_code = 200
|
|
||||||
return resp
|
|
||||||
|
|
||||||
@app.route("/health", methods=["GET"])
|
|
||||||
def healthy():
|
|
||||||
resp = jsonify("OK")
|
|
||||||
resp.status_code = 200
|
|
||||||
return resp
|
|
||||||
|
|
||||||
if mode == "debug":
|
|
||||||
app.run(host=CONFIG.webserver.host, port=CONFIG.webserver.port, debug=True)
|
|
||||||
elif mode == "production":
|
|
||||||
serve(app, host=CONFIG.webserver.host, port=CONFIG.webserver.port)
|
|
||||||
|
|
||||||
|
|
||||||
def get_storage():
|
def get_storage():
|
||||||
@ -87,8 +66,7 @@ def make_callback():
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
webserver = Process(target=run_probing_webserver, args=(set_up_probing_webserver(),))
|
||||||
webserver = Process(target=start_integrity_checks_webserver, args=("production",))
|
|
||||||
logging.info("Starting webserver...")
|
logging.info("Starting webserver...")
|
||||||
webserver.start()
|
webserver.start()
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user