forked from rDrama/rDrama
fix worker timeouts
parent
52d0a3dc7d
commit
3964a27281
|
@ -12,8 +12,6 @@ from flask import Flask
|
||||||
from flask_caching import Cache
|
from flask_caching import Cache
|
||||||
from flask_compress import Compress
|
from flask_compress import Compress
|
||||||
from flask_limiter import Limiter
|
from flask_limiter import Limiter
|
||||||
from sqlalchemy import *
|
|
||||||
from sqlalchemy.orm import scoped_session, sessionmaker
|
|
||||||
|
|
||||||
from files.helpers.config.const import *
|
from files.helpers.config.const import *
|
||||||
from files.helpers.const_stateful import const_initialize
|
from files.helpers.const_stateful import const_initialize
|
||||||
|
@ -48,7 +46,6 @@ app.config["PERMANENT_SESSION_LIFETIME"] = 60 * 60 * 24 * 999
|
||||||
app.config['SESSION_REFRESH_EACH_REQUEST'] = False
|
app.config['SESSION_REFRESH_EACH_REQUEST'] = False
|
||||||
|
|
||||||
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
||||||
app.config['SQLALCHEMY_DATABASE_URL'] = environ.get("DATABASE_URL").strip()
|
|
||||||
|
|
||||||
app.config["CACHE_KEY_PREFIX"] = f"{SITE}_flask_cache_"
|
app.config["CACHE_KEY_PREFIX"] = f"{SITE}_flask_cache_"
|
||||||
app.config["CACHE_TYPE"] = "RedisCache"
|
app.config["CACHE_TYPE"] = "RedisCache"
|
||||||
|
@ -74,11 +71,7 @@ limiter = Limiter(
|
||||||
storage_uri=app.config["CACHE_REDIS_URL"],
|
storage_uri=app.config["CACHE_REDIS_URL"],
|
||||||
)
|
)
|
||||||
|
|
||||||
engine = create_engine(app.config['SQLALCHEMY_DATABASE_URL'])
|
const_initialize()
|
||||||
|
|
||||||
db_session = scoped_session(sessionmaker(bind=engine))
|
|
||||||
|
|
||||||
const_initialize(db_session())
|
|
||||||
|
|
||||||
reload_settings()
|
reload_settings()
|
||||||
start_watching_settings()
|
start_watching_settings()
|
||||||
|
|
|
@ -1263,3 +1263,9 @@ GIRL_NAMES = {
|
||||||
'Y': ['Yesenia', 'Yasmine', 'Yasmin', 'Yvette', 'Yolanda', 'Yadira', 'Yvonne', 'Yamilet', 'Yazmin', 'Yasmeen', 'Yessenia'],
|
'Y': ['Yesenia', 'Yasmine', 'Yasmin', 'Yvette', 'Yolanda', 'Yadira', 'Yvonne', 'Yamilet', 'Yazmin', 'Yasmeen', 'Yessenia'],
|
||||||
'Z': ['Zoe', 'Zoey', 'Zaria', 'Zoie']
|
'Z': ['Zoe', 'Zoey', 'Zaria', 'Zoie']
|
||||||
}
|
}
|
||||||
|
|
||||||
|
from sqlalchemy import *
|
||||||
|
from sqlalchemy.orm import scoped_session, sessionmaker
|
||||||
|
|
||||||
|
engine = create_engine(environ.get("DATABASE_URL").strip())
|
||||||
|
db_session = scoped_session(sessionmaker(bind=engine))
|
||||||
|
|
|
@ -11,9 +11,11 @@ SNAPPY_MARSEYS = []
|
||||||
SNAPPY_QUOTES = []
|
SNAPPY_QUOTES = []
|
||||||
STEALTH_HOLES = []
|
STEALTH_HOLES = []
|
||||||
|
|
||||||
def const_initialize(db):
|
def const_initialize():
|
||||||
global marseys_const, marseys_const2, marsey_mappings, SNAPPY_KONGS, SNAPPY_MARSEYS, SNAPPY_QUOTES, STEALTH_HOLES
|
global marseys_const, marseys_const2, marsey_mappings, SNAPPY_KONGS, SNAPPY_MARSEYS, SNAPPY_QUOTES, STEALTH_HOLES
|
||||||
|
|
||||||
|
db = db_session()
|
||||||
|
|
||||||
marseys_const = [x[0] for x in db.query(Emoji.name).filter(Emoji.kind=="Marsey", Emoji.submitter_id==None, Emoji.name!='chudsey').all()]
|
marseys_const = [x[0] for x in db.query(Emoji.name).filter(Emoji.kind=="Marsey", Emoji.submitter_id==None, Emoji.name!='chudsey').all()]
|
||||||
marseys_const2 = marseys_const + ['chudsey','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','0','1','2','3','4','5','6','7','8','9','exclamationpoint','period','questionmark']
|
marseys_const2 = marseys_const + ['chudsey','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','0','1','2','3','4','5','6','7','8','9','exclamationpoint','period','questionmark']
|
||||||
marseys = db.query(Emoji).filter(Emoji.kind=="Marsey", Emoji.submitter_id==None).all()
|
marseys = db.query(Emoji).filter(Emoji.kind=="Marsey", Emoji.submitter_id==None).all()
|
||||||
|
|
|
@ -12,7 +12,6 @@ from werkzeug.utils import secure_filename
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
from PIL import UnidentifiedImageError
|
from PIL import UnidentifiedImageError
|
||||||
from PIL.ImageSequence import Iterator
|
from PIL.ImageSequence import Iterator
|
||||||
from sqlalchemy.orm.session import Session
|
|
||||||
|
|
||||||
from files.classes.media import *
|
from files.classes.media import *
|
||||||
from files.helpers.cloudflare import purge_files_in_cache
|
from files.helpers.cloudflare import purge_files_in_cache
|
||||||
|
@ -107,7 +106,7 @@ def process_audio(file, v):
|
||||||
return new
|
return new
|
||||||
|
|
||||||
|
|
||||||
def convert_to_mp4(old, new, vid, db):
|
def convert_to_mp4(old, new, vid):
|
||||||
tmp = new.replace('.mp4', '-t.mp4')
|
tmp = new.replace('.mp4', '-t.mp4')
|
||||||
try:
|
try:
|
||||||
subprocess.run(["ffmpeg", "-y", "-loglevel", "warning", "-nostats", "-threads:v", "1", "-i", old, "-map_metadata", "-1", tmp], check=True, stderr=subprocess.STDOUT, timeout=SUBPROCESS_TIMEOUT_DURATION)
|
subprocess.run(["ffmpeg", "-y", "-loglevel", "warning", "-nostats", "-threads:v", "1", "-i", old, "-map_metadata", "-1", tmp], check=True, stderr=subprocess.STDOUT, timeout=SUBPROCESS_TIMEOUT_DURATION)
|
||||||
|
@ -126,8 +125,15 @@ def convert_to_mp4(old, new, vid, db):
|
||||||
user_id=vid,
|
user_id=vid,
|
||||||
size=os.stat(new).st_size
|
size=os.stat(new).st_size
|
||||||
)
|
)
|
||||||
|
|
||||||
|
db = db_session()
|
||||||
db.add(media)
|
db.add(media)
|
||||||
|
|
||||||
|
try:
|
||||||
db.commit()
|
db.commit()
|
||||||
|
except:
|
||||||
|
db.rollback()
|
||||||
|
|
||||||
db.close()
|
db.close()
|
||||||
|
|
||||||
purge_files_in_cache(f"{SITE_FULL}{new}")
|
purge_files_in_cache(f"{SITE_FULL}{new}")
|
||||||
|
@ -152,8 +158,7 @@ def process_video(file, v):
|
||||||
if extension not in {'mp4','avi','mkv'}:
|
if extension not in {'mp4','avi','mkv'}:
|
||||||
new = new.replace(f'.{extension}', '.mp4')
|
new = new.replace(f'.{extension}', '.mp4')
|
||||||
copyfile(old, new)
|
copyfile(old, new)
|
||||||
db = Session(bind=g.db.get_bind())
|
gevent.spawn(convert_to_mp4, old, new, v.id)
|
||||||
gevent.spawn(convert_to_mp4, old, new, v.id, db)
|
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
subprocess.run(["ffmpeg", "-y", "-loglevel", "warning", "-nostats", "-i", old, "-map_metadata", "-1", "-c:v", "copy", "-c:a", "copy", new], check=True, timeout=SUBPROCESS_TIMEOUT_DURATION)
|
subprocess.run(["ffmpeg", "-y", "-loglevel", "warning", "-nostats", "-i", old, "-map_metadata", "-1", "-c:v", "copy", "-c:a", "copy", new], check=True, timeout=SUBPROCESS_TIMEOUT_DURATION)
|
||||||
|
|
Loading…
Reference in New Issue