mirror of
https://github.com/blw1138/Zordon.git
synced 2025-12-17 08:48:13 +00:00
Add unregister client and other improvements
This commit is contained in:
@@ -136,6 +136,11 @@ class RenderServer:
|
|||||||
found_jobs = sorted(found_jobs, key=lambda a: a.priority, reverse=False)
|
found_jobs = sorted(found_jobs, key=lambda a: a.priority, reverse=False)
|
||||||
return found_jobs
|
return found_jobs
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def job_with_id(cls, job_id):
|
||||||
|
found_job = next((x for x in cls.render_queue if x.id == job_id), None)
|
||||||
|
return found_job
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def clear_history(cls):
|
def clear_history(cls):
|
||||||
to_remove = [x for x in cls.render_queue if x.render_status() in [RenderStatus.CANCELLED,
|
to_remove = [x for x in cls.render_queue if x.render_status() in [RenderStatus.CANCELLED,
|
||||||
@@ -263,6 +268,7 @@ class RenderServer:
|
|||||||
stats = {"timestamp": datetime.now().isoformat(),
|
stats = {"timestamp": datetime.now().isoformat(),
|
||||||
"platform": platform.platform(),
|
"platform": platform.platform(),
|
||||||
"cpu_percent": psutil.cpu_percent(percpu=False),
|
"cpu_percent": psutil.cpu_percent(percpu=False),
|
||||||
|
"cpu_percent_per_cpu": psutil.cpu_percent(percpu=True),
|
||||||
"cpu_count": psutil.cpu_count(),
|
"cpu_count": psutil.cpu_count(),
|
||||||
"memory_total": psutil.virtual_memory().total,
|
"memory_total": psutil.virtual_memory().total,
|
||||||
"memory_available": psutil.virtual_memory().available,
|
"memory_available": psutil.virtual_memory().available,
|
||||||
@@ -299,8 +305,13 @@ class RenderServer:
|
|||||||
return success
|
return success
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def unregister_client(cls):
|
def unregister_client(cls, hostname):
|
||||||
pass
|
success = False
|
||||||
|
if hostname in cls.render_clients and hostname != cls.host_name:
|
||||||
|
cls.render_clients.remove(hostname)
|
||||||
|
logger.info(f"Client '{hostname}' successfully unregistered")
|
||||||
|
success = True
|
||||||
|
return success
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def start(cls, background_thread=False):
|
def start(cls, background_thread=False):
|
||||||
@@ -318,6 +329,7 @@ class RenderServer:
|
|||||||
|
|
||||||
app.config['UPLOAD_FOLDER'] = config['upload_folder']
|
app.config['UPLOAD_FOLDER'] = config['upload_folder']
|
||||||
app.config['MAX_CONTENT_PATH'] = config['max_content_path']
|
app.config['MAX_CONTENT_PATH'] = config['max_content_path']
|
||||||
|
app.config['RESULT_STATIC_PATH'] = 'static/'
|
||||||
|
|
||||||
# Get hostname and render clients
|
# Get hostname and render clients
|
||||||
cls.host_name = socket.gethostname()
|
cls.host_name = socket.gethostname()
|
||||||
@@ -351,7 +363,7 @@ class RenderServer:
|
|||||||
|
|
||||||
@app.get('/jobs')
|
@app.get('/jobs')
|
||||||
def jobs_json():
|
def jobs_json():
|
||||||
return jsonify([json.loads(x.json()) for x in RenderServer.render_queue if not x.archived])
|
return [json.loads(x.json()) for x in RenderServer.render_queue if not x.archived]
|
||||||
|
|
||||||
|
|
||||||
@app.get('/jobs/<status_val>')
|
@app.get('/jobs/<status_val>')
|
||||||
@@ -377,6 +389,13 @@ def register_client():
|
|||||||
return "Success" if x else "Fail"
|
return "Success" if x else "Fail"
|
||||||
|
|
||||||
|
|
||||||
|
@app.post('/unregister_client')
|
||||||
|
def unregister_client():
|
||||||
|
client_hostname = request.values['hostname']
|
||||||
|
x = RenderServer.unregister_client(client_hostname)
|
||||||
|
return "Success" if x else "Fail"
|
||||||
|
|
||||||
|
|
||||||
@app.get('/full_status')
|
@app.get('/full_status')
|
||||||
def full_status():
|
def full_status():
|
||||||
full_results = {'timestamp': datetime.now().isoformat(), 'servers': {}}
|
full_results = {'timestamp': datetime.now().isoformat(), 'servers': {}}
|
||||||
@@ -415,13 +434,16 @@ def snapshot():
|
|||||||
@app.post('/add_job')
|
@app.post('/add_job')
|
||||||
def add_job():
|
def add_job():
|
||||||
"""Create new job and add to server render queue"""
|
"""Create new job and add to server render queue"""
|
||||||
renderer = request.json["renderer"]
|
renderer = request.json.get("renderer", None)
|
||||||
input_path = request.json["input"]
|
input_path = request.json.get("input", None)
|
||||||
output_path = request.json["output"]
|
output_path = request.json.get("output", None)
|
||||||
priority = request.json.get('priority', 2)
|
priority = request.json.get('priority', 2)
|
||||||
args = request.json.get('args', None)
|
args = request.json.get('args', None)
|
||||||
force_start = request.json.get('force_start', False)
|
force_start = request.json.get('force_start', False)
|
||||||
|
|
||||||
|
if None in [renderer, input_path, output_path]:
|
||||||
|
return {'error': 'missing required parameters'}, 400
|
||||||
|
|
||||||
try:
|
try:
|
||||||
render_job = RenderWorkerFactory.create_worker(renderer, input_path, output_path, args)
|
render_job = RenderWorkerFactory.create_worker(renderer, input_path, output_path, args)
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
@@ -439,9 +461,9 @@ def cancel_job():
|
|||||||
job_id = request.args.get('id', None)
|
job_id = request.args.get('id', None)
|
||||||
confirm = request.args.get('confirm', False)
|
confirm = request.args.get('confirm', False)
|
||||||
if not job_id:
|
if not job_id:
|
||||||
return jsonify({'error': 'job id not found'})
|
return {'error': 'job id not found'}, 400
|
||||||
elif not confirm:
|
elif not confirm:
|
||||||
return jsonify({'error': 'confirmation required'})
|
return {'error': 'confirmation required'}, 400
|
||||||
else:
|
else:
|
||||||
found = [x for x in RenderServer.render_queue if x.id == job_id]
|
found = [x for x in RenderServer.render_queue if x.id == job_id]
|
||||||
if len(found) > 1:
|
if len(found) > 1:
|
||||||
@@ -450,18 +472,18 @@ def cancel_job():
|
|||||||
elif found:
|
elif found:
|
||||||
success = RenderServer.cancel_job(found[0])
|
success = RenderServer.cancel_job(found[0])
|
||||||
return jsonify({'result': success})
|
return jsonify({'result': success})
|
||||||
return jsonify({'error': 'job not found'})
|
return {'error': 'job not found'}, 400
|
||||||
|
|
||||||
|
|
||||||
@app.get('/clear_history')
|
@app.get('/clear_history')
|
||||||
def clear_history():
|
def clear_history():
|
||||||
RenderServer.clear_history()
|
RenderServer.clear_history()
|
||||||
return jsonify({'result': True})
|
return {'result': True}
|
||||||
|
|
||||||
|
|
||||||
@app.route('/status')
|
@app.route('/status')
|
||||||
def status():
|
def status():
|
||||||
return jsonify(RenderServer.status())
|
return RenderServer.status()
|
||||||
|
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
|
|||||||
Reference in New Issue
Block a user