1
0
mirror of https://github.com/krateng/maloja.git synced 2023-08-10 21:12:55 +03:00

Added waitress warning interception

This commit is contained in:
krateng 2022-04-13 17:51:17 +02:00
parent 42579ad1f0
commit 4a8221f7a0
3 changed files with 30 additions and 3 deletions

View File

@ -4,7 +4,7 @@
# you know what f*ck it # you know what f*ck it
# this is hardcoded for now because of that damn project / package name discrepancy # this is hardcoded for now because of that damn project / package name discrepancy
# i'll fix it one day # i'll fix it one day
VERSION = "3.0.1" VERSION = "3.0.2"
HOMEPAGE = "https://github.com/krateng/maloja" HOMEPAGE = "https://github.com/krateng/maloja"

View File

@ -6,6 +6,7 @@ import setproctitle
from importlib import resources from importlib import resources
from css_html_js_minify import html_minify, css_minify from css_html_js_minify import html_minify, css_minify
import datauri import datauri
import time
# server stuff # server stuff
@ -35,7 +36,7 @@ from .proccontrol.profiler import profile
PORT = malojaconfig["PORT"] PORT = malojaconfig["PORT"]
HOST = malojaconfig["HOST"] HOST = malojaconfig["HOST"]
THREADS = 12 THREADS = 16
BaseRequest.MEMFILE_MAX = 15 * 1024 * 1024 BaseRequest.MEMFILE_MAX = 15 * 1024 * 1024
#STATICFOLDER = importlib.resources.path(__name__,"web/static") #STATICFOLDER = importlib.resources.path(__name__,"web/static")
@ -296,6 +297,31 @@ def redirect_track(artists,title):
##### #####
# warning interception
import logging
class WaitressLogHandler():
def __init__(self):
self.lastwarned = 0
self.barrier = 5
self.level = 20
self.filters = []
def handle(self,record):
if record.name == 'waitress.queue':
now = time.time()
depth = record.args[0]
if depth > self.barrier:
log(f"Waitress Task Queue Depth at {depth}")
self.lastwarned = now
self.barrier = max(depth,self.barrier+5)
elif now - self.lastwarned > 5:
self.barrier = max(5,self.barrier-5)
else:
log(f"Waitress: {record.msg % record.args}")
logging.getLogger().addHandler(WaitressLogHandler())
def run_server(): def run_server():
log("Starting up Maloja server...") log("Starting up Maloja server...")
@ -303,6 +329,7 @@ def run_server():
Thread(target=database.start_db).start() Thread(target=database.start_db).start()
try: try:
#run(webserver, host=HOST, port=MAIN_PORT, server='waitress') #run(webserver, host=HOST, port=MAIN_PORT, server='waitress')
log(f"Listening on {HOST}:{PORT}") log(f"Listening on {HOST}:{PORT}")

View File

@ -1,6 +1,6 @@
[project] [project]
name = "malojaserver" name = "malojaserver"
version = "3.0.1" version = "3.0.2"
description = "Self-hosted music scrobble database" description = "Self-hosted music scrobble database"
readme = "./README.md" readme = "./README.md"
requires-python = ">=3.6" requires-python = ">=3.6"