and get it working

condor-scripts
Mike Lang 3 years ago
parent 04ae9dd695
commit a236509470

@ -92,6 +92,8 @@
dbname: "wubloader", dbname: "wubloader",
}, },
condor_db:: "mysql://necrobot-read:necrobot-read@condor.live/condor_x2",
// Other database arguments // Other database arguments
db_super_user:: "postgres", // only accessible from localhost db_super_user:: "postgres", // only accessible from localhost
db_super_password:: "postgres", // Must not contain ' or \ as these are not escaped. db_super_password:: "postgres", // Must not contain ' or \ as these are not escaped.
@ -216,7 +218,9 @@
command: [ command: [
"--base-dir", "/mnt", "--base-dir", "/mnt",
"--backdoor-port", std.toString($.backdoor_port), "--backdoor-port", std.toString($.backdoor_port),
], ] + (if $.condor_db == null then [] else [
"--condor-db", $.condor_db,
]),
environment: $.env, environment: $.env,
}, },

@ -10,6 +10,7 @@ import time
import uuid import uuid
from base64 import b64encode from base64 import b64encode
from contextlib import contextmanager from contextlib import contextmanager
from urlparse import urlparse
import argh import argh
import gevent import gevent
@ -595,11 +596,11 @@ class SegmentGetter(object):
"Twitch channels to watch. Add a '!' suffix to indicate they're expected to be always up. " "Twitch channels to watch. Add a '!' suffix to indicate they're expected to be always up. "
"This affects retry interval, error reporting and monitoring." "This affects retry interval, error reporting and monitoring."
) )
@argh.arg('--league-db', default="necrobot-read:necrobot-read@condor.live/condor_x2", help= @argh.arg('--condor-db', default="mysql://necrobot-read:necrobot-read@condor.live/condor_x2", help=
"Connection string for database to check for racers and commentators. " "Connection string for database to check for racers and commentators. "
"Should be of form USER:PASSWORD@HOST/DATABASE.", "Should be of form mysql://USER:PASSWORD@HOST/DATABASE.",
) )
def main(channels, base_dir=".", qualities="source", metrics_port=8001, backdoor_port=0, league_db=None): def main(channels, base_dir=".", qualities="source", metrics_port=8001, backdoor_port=0, condor_db=None):
qualities = qualities.split(",") if qualities else [] qualities = qualities.split(",") if qualities else []
managers = {} managers = {}
@ -620,10 +621,12 @@ def main(channels, base_dir=".", qualities="source", metrics_port=8001, backdoor
if backdoor_port: if backdoor_port:
gevent.backdoor.BackdoorServer(('127.0.0.1', backdoor_port), locals=locals()).start() gevent.backdoor.BackdoorServer(('127.0.0.1', backdoor_port), locals=locals()).start()
if league_db: if condor_db:
user, rest = league_db.split(':', 1) db_args = urlparse(condor_db)
password, rest = rest.split('@', 1) user = db_args.username
host, db = rest.split('/', 1) password = db_args.password
host = db_args.hostname
db = db_args.path.lstrip('/')
prev_check = 0 prev_check = 0
CHECK_INTERVAL = 60 CHECK_INTERVAL = 60
@ -632,7 +635,7 @@ def main(channels, base_dir=".", qualities="source", metrics_port=8001, backdoor
for channel in managers.keys(): for channel in managers.keys():
logging.info("Stopping channel {} for shutdown".format(channel)) logging.info("Stopping channel {} for shutdown".format(channel))
managers.pop(channel).stop() managers.pop(channel).stop()
elif league_db and time.time() - prev_check > CHECK_INTERVAL: elif condor_db and time.time() - prev_check > CHECK_INTERVAL:
logging.info("Checking for new racers") logging.info("Checking for new racers")
prev_check = time.time() prev_check = time.time()
try: try:

@ -9,7 +9,7 @@ setup(
"python-dateutil", "python-dateutil",
"gevent", "gevent",
"monotonic", "monotonic",
"mysql-connector-python", "mysql-connector-python==8.0.5", # old version for py2 compat
"prometheus-client==0.7.1", # locked version as we rely on internals "prometheus-client==0.7.1", # locked version as we rely on internals
"requests", "requests",
"wubloader-common", "wubloader-common",

@ -369,7 +369,7 @@ def review_race(match_id, race_number):
if app.condor_db is None: if app.condor_db is None:
return "Reviews are disabled", 501 return "Reviews are disabled", 501
start_range = map(float, request.args.get('start_range', '0,5').split(',')) start_range = map(float, request.args.get('start_range', '0,5').split(','))
finish_range = map(float, request.args.get('finish_range', '0,5').split(',')) finish_range = map(float, request.args.get('finish_range', '-5,10').split(','))
try: try:
review_path = review(match_id, race_number, app.static_folder, app.condor_db, start_range, finish_range) review_path = review(match_id, race_number, app.static_folder, app.condor_db, start_range, finish_range)
except RaceNotFound as e: except RaceNotFound as e:

@ -104,7 +104,7 @@ def review(match_id, race_number, base_dir, db_url, start_range=(0, 5), finish_r
] ]
if not data: if not data:
raise RaceNotFound("Could not find race number {} of match {}".format(match_id, race_number)) raise RaceNotFound("Could not find race number {} of match {}".format(race_number, match_id))
assert len(data) == 1, repr(data) assert len(data) == 1, repr(data)
(racer1, racer2, start, duration), = data (racer1, racer2, start, duration), = data
@ -112,7 +112,9 @@ def review(match_id, race_number, base_dir, db_url, start_range=(0, 5), finish_r
output_name = "{}-{}-{}-{}".format(match_id, racer1, racer2, race_number) output_name = "{}-{}-{}-{}".format(match_id, racer1, racer2, race_number)
output_dir = os.path.join(base_dir, "reviews", output_name) output_dir = os.path.join(base_dir, "reviews", output_name)
result_name = "review.{}.{}.mp4".format(*finish_range) if not os.path.exists(output_dir):
os.makedirs(output_dir)
result_name = "review_{}_{}.mp4".format(*finish_range)
result_path = os.path.join(output_dir, result_name) result_path = os.path.join(output_dir, result_name)
if os.path.exists(result_path): if os.path.exists(result_path):
logger.info("Result already exists for {}, reusing".format(result_path)) logger.info("Result already exists for {}, reusing".format(result_path))

@ -10,6 +10,7 @@ setup(
"flask", "flask",
"gevent", "gevent",
"monotonic", "monotonic",
"mysql-connector-python==8.0.5", # old version for py2 compat
"prometheus-client", "prometheus-client",
"wubloader-common", "wubloader-common",
], ],

Loading…
Cancel
Save