fix blocking behavior
This commit is contained in:
parent
c1ee80ce1d
commit
7a75a5868e
10
app.py
10
app.py
@ -1,3 +1,5 @@
|
|||||||
|
import eventlet
|
||||||
|
eventlet.monkey_patch()
|
||||||
from flask import Flask, render_template, send_file, url_for, jsonify, request, session, send_from_directory, make_response, abort
|
from flask import Flask, render_template, send_file, url_for, jsonify, request, session, send_from_directory, make_response, abort
|
||||||
import os
|
import os
|
||||||
from PIL import Image, ImageOps
|
from PIL import Image, ImageOps
|
||||||
@ -256,13 +258,15 @@ def serve_file(subpath):
|
|||||||
mime, _ = mimetypes.guess_type(full_path)
|
mime, _ = mimetypes.guess_type(full_path)
|
||||||
mime = mime or 'application/octet-stream'
|
mime = mime or 'application/octet-stream'
|
||||||
is_cache_request = request.headers.get('X-Cache-Request') == 'true'
|
is_cache_request = request.headers.get('X-Cache-Request') == 'true'
|
||||||
|
is_audio_get = mime.startswith('audio/') and request.method == 'GET'
|
||||||
ip_address = request.remote_addr
|
ip_address = request.remote_addr
|
||||||
user_agent = request.headers.get('User-Agent')
|
user_agent = request.headers.get('User-Agent')
|
||||||
|
|
||||||
# skip logging on cache hits or on audio GETs (per your rules)
|
# skip logging on cache hits or on audio GETs (per your rules)
|
||||||
do_log = not is_cache_request
|
do_log = (
|
||||||
if mime == 'audio/mpeg' and request.method != 'HEAD':
|
not is_cache_request # skip if upstream CDN asked us to cache
|
||||||
do_log = False
|
and not is_audio_get # skip audio GETs
|
||||||
|
)
|
||||||
|
|
||||||
# 3) Pick cache
|
# 3) Pick cache
|
||||||
if mime.startswith('audio/'):
|
if mime.startswith('audio/'):
|
||||||
|
|||||||
@ -40,7 +40,7 @@ services:
|
|||||||
# Production-ready Gunicorn command with eventlet
|
# Production-ready Gunicorn command with eventlet
|
||||||
command: >
|
command: >
|
||||||
sh -c "pip install -r requirements.txt &&
|
sh -c "pip install -r requirements.txt &&
|
||||||
gunicorn --worker-class eventlet -w 4 -b 0.0.0.0:5000 app:app"
|
gunicorn --worker-class eventlet -w 1 -b 0.0.0.0:5000 app:app"
|
||||||
|
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user