Files
nathanwoodburn ba8b391ecd
Build Docker / Build Image (push) Successful in 53s
fix: Status route
2026-08-24 15:50:24 +10:00

65 lines
1.9 KiB
Python

import time
from flask import Flask
from server import app
import server
from gunicorn.app.base import BaseApplication
import os
import dotenv
import sys
import json
from apscheduler.schedulers.background import BackgroundScheduler
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:
self.cfg.set(key.lower(), value)
def load(self):
return self.application
import nextcloud
if __name__ == '__main__':
# Pre-warm Nextcloud cache at startup so incoming connections are served instantly
try:
print("[Startup] Pre-warming Nextcloud cache...", flush=True)
nextcloud.nextcloud_provider.warm_cache(force=True)
print("[Startup] Nextcloud cache hydrated successfully.", flush=True)
except Exception as e:
print(f"[Startup] Warning: Initial Nextcloud cache pre-warm failed: {e}", flush=True)
scheduler = BackgroundScheduler()
scheduler.add_job(func=server.check_payments, trigger="interval", seconds=10)
scheduler.add_job(
func=nextcloud.nextcloud_provider.warm_cache,
trigger="interval",
seconds=60,
id="nextcloud_cache_sync",
replace_existing=True,
)
scheduler.start()
workers = os.getenv('WORKERS')
threads = os.getenv('THREADS')
if workers is None:
workers = 1
if threads is None:
threads = 2
workers = int(workers)
threads = int(threads)
options = {
'bind': '0.0.0.0:5000',
'workers': workers,
'threads': threads,
}
gunicorn_app = GunicornApp(app, options)
print('Starting server with ' + str(workers) + ' workers and ' + str(threads) + ' threads', flush=True)
gunicorn_app.run()