Files
firealerts/main.py
Nathan Woodburn 1ac41d5582
All checks were successful
Build Docker / BuildImage (push) Successful in 58s
feat: Add scheduler and fix some types
2025-07-24 16:33:31 +10:00

63 lines
1.7 KiB
Python

from flask import Flask
from server import app
import server
from gunicorn.app.base import BaseApplication
import os
import dotenv
import threading
import time
import domains
class GunicornApp(BaseApplication):
def __init__(self, app, options=None):
self.options = options or {}
self.application = app
super().__init__()
def load_config(self):
for key, value in self.options.items():
if key in self.cfg.settings and value is not None: # type: ignore
self.cfg.set(key.lower(), value) # type: ignore
def load(self):
return self.application
def run_expiry_checker():
"""
Background function to run notify_expiries every 2 minutes.
"""
while True:
try:
print("Running expiry check...")
domains.notify_expiries()
print("Expiry check completed.")
except Exception as e:
print(f"Error in expiry checker: {e}")
# Wait 2 minutes (120 seconds)
time.sleep(120)
if __name__ == '__main__':
dotenv.load_dotenv()
# Start the background expiry checker
expiry_thread = threading.Thread(target=run_expiry_checker, daemon=True)
expiry_thread.start()
print("Started background expiry checker thread")
workers = os.getenv('WORKERS', 1)
threads = os.getenv('THREADS', 2)
workers = int(workers)
threads = int(threads)
options = {
'bind': '0.0.0.0:5000',
'workers': workers,
'threads': threads,
}
gunicorn_app = GunicornApp(server.app, options)
print(f'Starting server with {workers} workers and {threads} threads', flush=True)
gunicorn_app.run()