refactor: remove dashboard startup function and adjust message deletion schedule
This commit is contained in:
@@ -162,34 +162,6 @@ def get_next_scheduled_event(now: datetime | None = None) -> dict:
|
|||||||
return {"at": next_dt, "type": next_type}
|
return {"at": next_dt, "type": next_type}
|
||||||
|
|
||||||
|
|
||||||
def start_dashboard() -> None:
|
|
||||||
"""Start the minimal dashboard in a background thread."""
|
|
||||||
enabled = os.getenv("DASHBOARD_ENABLED", "1").strip().lower() not in {
|
|
||||||
"0", "false", "no"}
|
|
||||||
if not enabled:
|
|
||||||
return
|
|
||||||
|
|
||||||
host = os.getenv("DASHBOARD_HOST", "0.0.0.0")
|
|
||||||
port = int(os.getenv("DASHBOARD_PORT", "8080"))
|
|
||||||
|
|
||||||
def _run() -> None:
|
|
||||||
try:
|
|
||||||
from dashboard import create_app
|
|
||||||
|
|
||||||
app = create_app(
|
|
||||||
get_state=get_state_snapshot,
|
|
||||||
get_next_event=lambda: get_next_scheduled_event(),
|
|
||||||
)
|
|
||||||
app.config["TEMPLATES_PATH"] = os.getenv(
|
|
||||||
"TEMPLATES_PATH", "templates.json")
|
|
||||||
app.run(host=host, port=port, debug=False, use_reloader=False)
|
|
||||||
except Exception as e:
|
|
||||||
logging.error(f"Dashboard failed to start: {e}")
|
|
||||||
|
|
||||||
thread = threading.Thread(target=_run, name="dashboard", daemon=True)
|
|
||||||
thread.start()
|
|
||||||
|
|
||||||
|
|
||||||
def load_timezones() -> list[dict]:
|
def load_timezones() -> list[dict]:
|
||||||
"""Load timezones from csv file."""
|
"""Load timezones from csv file."""
|
||||||
# Read the CSV file and return a list of timezones
|
# Read the CSV file and return a list of timezones
|
||||||
@@ -302,11 +274,11 @@ def should_delete_message(
|
|||||||
message: dict,
|
message: dict,
|
||||||
webhook_id: str,
|
webhook_id: str,
|
||||||
author_id: str,
|
author_id: str,
|
||||||
five_minutes_ago_timestamp: int,
|
cutoff: int,
|
||||||
) -> bool:
|
) -> bool:
|
||||||
message_timestamp = int(parse_message_timestamp(message).timestamp())
|
message_timestamp = int(parse_message_timestamp(message).timestamp())
|
||||||
return (
|
return (
|
||||||
message_timestamp <= five_minutes_ago_timestamp
|
message_timestamp <= cutoff
|
||||||
and message.get("webhook_id") == webhook_id
|
and message.get("webhook_id") == webhook_id
|
||||||
and message.get("author", {}).get("id") == author_id
|
and message.get("author", {}).get("id") == author_id
|
||||||
)
|
)
|
||||||
@@ -744,16 +716,14 @@ def main() -> None:
|
|||||||
"""
|
"""
|
||||||
Main function to run the scheduler.
|
Main function to run the scheduler.
|
||||||
"""
|
"""
|
||||||
# start_dashboard()
|
|
||||||
|
|
||||||
# Schedule notifications
|
# Schedule notifications
|
||||||
schedule.every().hour.at(":15").do(send_notification, "reminder")
|
schedule.every().hour.at(":15").do(send_notification, "reminder")
|
||||||
schedule.every().hour.at(":20").do(send_notification, "420")
|
schedule.every().hour.at(":20").do(send_notification, "420")
|
||||||
# schedule.every().hour.at(":45").do(send_notification, "reminder_halftime")
|
# schedule.every().hour.at(":45").do(send_notification, "reminder_halftime")
|
||||||
# schedule.every().hour.at(":50").do(send_notification, "halftime")
|
# schedule.every().hour.at(":50").do(send_notification, "halftime")
|
||||||
|
|
||||||
# Schedule deletion of old messages every 3 minutes
|
# Schedule deletion of old messages every 5 minutes
|
||||||
schedule.every(3).minutes.do(delete_old_messages, 6)
|
schedule.every(5).minutes.do(delete_old_messages, 6)
|
||||||
|
|
||||||
logging.info("Scheduler started.")
|
logging.info("Scheduler started.")
|
||||||
|
|
||||||
@@ -761,7 +731,7 @@ def main() -> None:
|
|||||||
# send_notification("420")
|
# send_notification("420")
|
||||||
|
|
||||||
# delete old messages on startup to clean up any previous notifications
|
# delete old messages on startup to clean up any previous notifications
|
||||||
delete_old_messages(60)
|
# delete_old_messages(6)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
|
|||||||
Reference in New Issue
Block a user