refactor: Extract auto-stop timeout constant
This commit is contained in:
parent
960fe60cf7
commit
ed90b36233
11
main.py
11
main.py
|
@ -6,6 +6,9 @@ logging.basicConfig(
|
||||||
|
|
||||||
from flask import Flask, request
|
from flask import Flask, request
|
||||||
|
|
||||||
|
# Constants
|
||||||
|
AUTO_STOP_TIMEOUT_SECONDS = 3600.0 # 1 hour
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
auto_stop_timer = None # Timer for automatic VNC stop
|
auto_stop_timer = None # Timer for automatic VNC stop
|
||||||
|
|
||||||
|
@ -24,9 +27,9 @@ def cast_spell():
|
||||||
if auto_stop_timer is not None and auto_stop_timer.is_alive():
|
if auto_stop_timer is not None and auto_stop_timer.is_alive():
|
||||||
auto_stop_timer.cancel()
|
auto_stop_timer.cancel()
|
||||||
logging.info("Cancelled previous auto-stop timer.")
|
logging.info("Cancelled previous auto-stop timer.")
|
||||||
auto_stop_timer = threading.Timer(3600.0, _auto_stop_vnc) # 1 hour
|
auto_stop_timer = threading.Timer(AUTO_STOP_TIMEOUT_SECONDS, _auto_stop_vnc)
|
||||||
auto_stop_timer.start()
|
auto_stop_timer.start()
|
||||||
logging.info("Scheduled auto-stop for VNC in 1 hour.")
|
logging.info(f"Scheduled auto-stop for VNC in {AUTO_STOP_TIMEOUT_SECONDS / 3600} hour(s).")
|
||||||
return f"Successfully cast to Trotec.", 200
|
return f"Successfully cast to Trotec.", 200
|
||||||
elif machine == "thunder":
|
elif machine == "thunder":
|
||||||
logging.info("Casting to Thunder.")
|
logging.info("Casting to Thunder.")
|
||||||
|
@ -36,9 +39,9 @@ def cast_spell():
|
||||||
if auto_stop_timer is not None and auto_stop_timer.is_alive():
|
if auto_stop_timer is not None and auto_stop_timer.is_alive():
|
||||||
auto_stop_timer.cancel()
|
auto_stop_timer.cancel()
|
||||||
logging.info("Cancelled previous auto-stop timer.")
|
logging.info("Cancelled previous auto-stop timer.")
|
||||||
auto_stop_timer = threading.Timer(3600.0, _auto_stop_vnc) # 1 hour
|
auto_stop_timer = threading.Timer(AUTO_STOP_TIMEOUT_SECONDS, _auto_stop_vnc)
|
||||||
auto_stop_timer.start()
|
auto_stop_timer.start()
|
||||||
logging.info("Scheduled auto-stop for VNC in 1 hour.")
|
logging.info(f"Scheduled auto-stop for VNC in {AUTO_STOP_TIMEOUT_SECONDS / 3600} hour(s).")
|
||||||
return f"Successfully cast to Thunder.", 200
|
return f"Successfully cast to Thunder.", 200
|
||||||
else:
|
else:
|
||||||
logging.warning(f"Invalid or missing machine parameter: {machine}")
|
logging.warning(f"Invalid or missing machine parameter: {machine}")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user