feat(api): add status endpoint
This commit is contained in:
parent
ac7657defd
commit
157ed6da70
|
@ -1,7 +1,7 @@
|
||||||
from concurrent.futures import Future, ThreadPoolExecutor, ProcessPoolExecutor
|
from concurrent.futures import Future, ThreadPoolExecutor, ProcessPoolExecutor
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
from multiprocessing import Value
|
from multiprocessing import Value
|
||||||
from typing import Any, Callable, List, Optional, Tuple, Union
|
from typing import Any, Callable, Dict, List, Optional, Tuple, Union
|
||||||
|
|
||||||
logger = getLogger(__name__)
|
logger = getLogger(__name__)
|
||||||
|
|
||||||
|
@ -121,3 +121,6 @@ class DevicePoolExecutor:
|
||||||
future = self.pool.submit(fn, context, *args, **kwargs)
|
future = self.pool.submit(fn, context, *args, **kwargs)
|
||||||
job = Job(key, future, context)
|
job = Job(key, future, context)
|
||||||
self.jobs.append(job)
|
self.jobs.append(job)
|
||||||
|
|
||||||
|
def status(self) -> Dict[str, Tuple[bool, int]]:
|
||||||
|
return [(job.future.done(), job.get_progress()) for job in self.jobs]
|
|
@ -606,6 +606,15 @@ def chain():
|
||||||
return jsonify(json_params(output, params, size))
|
return jsonify(json_params(output, params, size))
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/api/cancel', methods=['PUT'])
|
||||||
|
def cancel():
|
||||||
|
output_file = request.args.get('output', None)
|
||||||
|
|
||||||
|
cancel = executor.cancel(output_file)
|
||||||
|
|
||||||
|
return ready_reply(cancel)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/api/ready')
|
@app.route('/api/ready')
|
||||||
def ready():
|
def ready():
|
||||||
output_file = request.args.get('output', None)
|
output_file = request.args.get('output', None)
|
||||||
|
@ -620,13 +629,9 @@ def ready():
|
||||||
return ready_reply(done, progress=progress)
|
return ready_reply(done, progress=progress)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/api/cancel', methods=['PUT'])
|
@app.route('/api/status')
|
||||||
def cancel():
|
def status():
|
||||||
output_file = request.args.get('output', None)
|
return jsonify(executor.status())
|
||||||
|
|
||||||
cancel = executor.cancel(output_file)
|
|
||||||
|
|
||||||
return ready_reply(cancel)
|
|
||||||
|
|
||||||
|
|
||||||
@app.route('/output/<path:filename>')
|
@app.route('/output/<path:filename>')
|
||||||
|
|
Loading…
Reference in New Issue