remove global proxy_is_up
This commit is contained in:
@@ -17,7 +17,18 @@ from cnf.config_read_toml import ConfigReadToml
|
|||||||
from cnf.config_read_json import ConfigReadJson
|
from cnf.config_read_json import ConfigReadJson
|
||||||
from modbus_tcp import ModbusTcp
|
from modbus_tcp import ModbusTcp
|
||||||
|
|
||||||
proxy_is_up = False
|
|
||||||
|
class ProxyState:
|
||||||
|
_is_up = False
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def is_up() -> bool:
|
||||||
|
return ProxyState._is_up
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def set_up(value: bool):
|
||||||
|
ProxyState._is_up = value
|
||||||
|
|
||||||
|
|
||||||
app = Quart(__name__)
|
app = Quart(__name__)
|
||||||
|
|
||||||
@@ -29,7 +40,7 @@ async def hello():
|
|||||||
|
|
||||||
@app.route('/-/ready')
|
@app.route('/-/ready')
|
||||||
async def ready():
|
async def ready():
|
||||||
if proxy_is_up:
|
if ProxyState.is_up():
|
||||||
status = 200
|
status = 200
|
||||||
text = 'Is ready'
|
text = 'Is ready'
|
||||||
else:
|
else:
|
||||||
@@ -41,7 +52,7 @@ async def ready():
|
|||||||
@app.route('/-/healthy')
|
@app.route('/-/healthy')
|
||||||
async def healthy():
|
async def healthy():
|
||||||
|
|
||||||
if proxy_is_up:
|
if ProxyState.is_up():
|
||||||
# logging.info('web reqeust healthy()')
|
# logging.info('web reqeust healthy()')
|
||||||
for inverter in InverterIfc:
|
for inverter in InverterIfc:
|
||||||
try:
|
try:
|
||||||
@@ -62,13 +73,12 @@ async def handle_client(reader: StreamReader, writer: StreamWriter, inv_class):
|
|||||||
|
|
||||||
|
|
||||||
@app.after_serving
|
@app.after_serving
|
||||||
async def handle_shutdown():
|
async def handle_shutdown(): # pragma: no cover
|
||||||
'''Close all TCP connections and stop the event loop'''
|
'''Close all TCP connections and stop the event loop'''
|
||||||
|
|
||||||
logging.info('Shutdown due to SIGTERM')
|
logging.info('Shutdown due to SIGTERM')
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
global proxy_is_up
|
ProxyState.set_up(False)
|
||||||
proxy_is_up = False
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# first, disc all open TCP connections gracefully
|
# first, disc all open TCP connections gracefully
|
||||||
@@ -190,8 +200,7 @@ def main(): # pragma: no cover
|
|||||||
|
|
||||||
loop.set_debug(log_level == logging.DEBUG)
|
loop.set_debug(log_level == logging.DEBUG)
|
||||||
try:
|
try:
|
||||||
global proxy_is_up
|
ProxyState.set_up(True)
|
||||||
proxy_is_up = True
|
|
||||||
logging.info("Start Quart")
|
logging.info("Start Quart")
|
||||||
app.run(host='0.0.0.0', port=8127, use_reloader=False, loop=loop)
|
app.run(host='0.0.0.0', port=8127, use_reloader=False, loop=loop)
|
||||||
logging.info("Quart stopped")
|
logging.info("Quart stopped")
|
||||||
|
|||||||
Reference in New Issue
Block a user