feat: Add initial telegram functions
All checks were successful
Build Docker / BuildImage (push) Successful in 1m0s

This commit is contained in:
2025-07-25 15:33:56 +10:00
parent e2d0122f91
commit 61cc135a6f
8 changed files with 413 additions and 18 deletions

17
main.py
View File

@@ -7,6 +7,7 @@ import dotenv
import threading
import time
import domains
from alerts import startTGBot, stopTGBot
class GunicornApp(BaseApplication):
@@ -38,6 +39,19 @@ def run_expiry_checker():
# Wait 2 minutes (120 seconds)
time.sleep(120)
def post_worker_init(worker):
"""
Called just after a worker has been forked.
Start the Telegram bot in each worker process.
"""
print(f"Starting Telegram bot in worker {worker.pid}")
startTGBot(mainThread=True)
# Register cleanup function for this worker
import atexit
atexit.register(stopTGBot)
if __name__ == '__main__':
dotenv.load_dotenv()
@@ -46,6 +60,8 @@ if __name__ == '__main__':
expiry_thread.start()
print("Started background expiry checker thread")
# Don't start the Telegram bot here - it will be started in worker processes
workers = os.getenv('WORKERS', 1)
threads = os.getenv('THREADS', 2)
workers = int(workers)
@@ -55,6 +71,7 @@ if __name__ == '__main__':
'bind': '0.0.0.0:5000',
'workers': workers,
'threads': threads,
'post_worker_init': post_worker_init,
}
gunicorn_app = GunicornApp(server.app, options)