moving website_dir to client side session cookie maybe this will allow multiple gunicorn workers?
This commit is contained in:
parent
17d87d1ed2
commit
a021840b59
13
app.py
13
app.py
|
@ -17,10 +17,9 @@ WEBSITE_DIRS = [name for name in os.listdir(ROOT_DIR) if not name.startswith('.'
|
||||||
website_dir = None
|
website_dir = None
|
||||||
def current_website_dir():
|
def current_website_dir():
|
||||||
if session['requests'] % 5 == 0:
|
if session['requests'] % 5 == 0:
|
||||||
global website_dir
|
session['website_dir'] = str(ROOT_DIR+"/Marvel")
|
||||||
website_dir = str(ROOT_DIR+"/Marvel")
|
|
||||||
elif session['requests'] % 6 == 0:
|
elif session['requests'] % 6 == 0:
|
||||||
website_dir = str(ROOT_DIR+"/Escape")
|
session['website_dir'] = str(ROOT_DIR+"/Escape")
|
||||||
session.pop('requests', None)
|
session.pop('requests', None)
|
||||||
else:
|
else:
|
||||||
global WEBSITE_DIRS
|
global WEBSITE_DIRS
|
||||||
|
@ -29,12 +28,12 @@ def current_website_dir():
|
||||||
WEBSITE_DIRS.remove(os.path.isdir(os.path.join(ROOT_DIR, 'Marvel')))
|
WEBSITE_DIRS.remove(os.path.isdir(os.path.join(ROOT_DIR, 'Marvel')))
|
||||||
except (ValueError, IndexError) as e:
|
except (ValueError, IndexError) as e:
|
||||||
pass
|
pass
|
||||||
website_dir = random.choice(WEBSITE_DIRS)
|
session['website_dir'] = random.choice(WEBSITE_DIRS)
|
||||||
|
|
||||||
# Make static files available
|
# Make static files available
|
||||||
@app.route('/<path:filename>', methods=['GET'])
|
@app.route('/<path:filename>', methods=['GET'])
|
||||||
def static_proxy(filename):
|
def static_proxy(filename):
|
||||||
return send_from_directory(website_dir, filename)
|
return send_from_directory(session['website_dir'], filename)
|
||||||
|
|
||||||
# Serve site index.html
|
# Serve site index.html
|
||||||
@app.route('/', methods=['GET'])
|
@app.route('/', methods=['GET'])
|
||||||
|
@ -44,7 +43,7 @@ def index():
|
||||||
else:
|
else:
|
||||||
session['requests'] = 1
|
session['requests'] = 1
|
||||||
current_website_dir()
|
current_website_dir()
|
||||||
return send_from_directory(website_dir, 'index.html')
|
return send_from_directory(session['website_dir'], 'index.html')
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app.run()
|
app.run(debug=True)
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
bind = "0.0.0.0:8080"
|
bind = "0.0.0.0:8080"
|
||||||
workers = 1
|
workers = 2
|
||||||
|
|
Loading…
Reference in New Issue