Skip to content

Commit

Permalink
feat(api): add status endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Feb 4, 2023
1 parent ac7657d commit 157ed6d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
5 changes: 4 additions & 1 deletion api/onnx_web/device_pool.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from concurrent.futures import Future, ThreadPoolExecutor, ProcessPoolExecutor
from logging import getLogger
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__)

Expand Down Expand Up @@ -121,3 +121,6 @@ def submit(self, key: str, fn: Callable[..., None], /, *args, **kwargs) -> None:
future = self.pool.submit(fn, context, *args, **kwargs)
job = Job(key, future, context)
self.jobs.append(job)

def status(self) -> Dict[str, Tuple[bool, int]]:
return [(job.future.done(), job.get_progress()) for job in self.jobs]
19 changes: 12 additions & 7 deletions api/onnx_web/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,15 @@ def chain():
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')
def ready():
output_file = request.args.get('output', None)
Expand All @@ -620,13 +629,9 @@ def ready():
return ready_reply(done, progress=progress)


@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/status')
def status():
return jsonify(executor.status())


@app.route('/output/<path:filename>')
Expand Down

0 comments on commit 157ed6d

Please sign in to comment.