Skip to content
This repository has been archived by the owner on Feb 22, 2020. It is now read-only.

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
felix committed Jul 17, 2019
1 parent 25f0380 commit 46e026b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.git/
.pyre/
.idea/
docker-push.sh
Expand Down
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
FROM gnes/build-base:latest AS dependency
FROM gnes/build-base:dev AS dependency

WORKDIR /nes/

COPY setup.py ./setup.py

RUN python -c "import distutils.core;s=distutils.core.run_setup('setup.py').install_requires;f=open('requirements_tmp.txt', 'w');[f.write(v+'\n') for v in s];f.close()" && cat requirements_tmp.txt

RUN pip install -r requirements_tmp.txt
RUN pip --no-cache-dir install -r requirements_tmp.txt

FROM dependency as base

ADD . ./

RUN pip install .[all] \

RUN pip --no-cache-dir install .[all] \
&& rm -rf /tmp/*

WORKDIR /
Expand Down
23 changes: 20 additions & 3 deletions gnes/client/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,30 @@ def start(self):

async def general_handler(request, parser, *args, **kwargs):
try:
data = await asyncio.wait_for(request.json(), 10)
data = dict()
# # Option 1: uploading streaming chunk data
# data = b""
# async for chunk in request.content.iter_any():
# data += chunk
# self.logger.info("received %d content" % len(data))

# Option 2: uploading via Multipart-Encoded File
post_data = await request.post()
if 'query' in post_data.keys():
_file = post_data.get('query')
self.logger.info("query request from input file: %s" % _file.filename)
data['query'] = _file.file.read()
elif 'docs' in post_data.keys():
files = post_data.getall("docs")
self.logger.info("index request from input files: %d files" % len(files))
data['docs'] = [_file.file.read() for _file in files]

self.logger.info('data received, beigin processing')
resp = await loop.run_in_executor(
executor,
stub_call,
parser([d.encode() for d in data.get('docs')] if hasattr(data, 'docs')
else data.get('query').encode(), *args, **kwargs))
parser([d for d in data.get('docs')] if hasattr(data, 'docs')
else data.get('query'), *args, **kwargs))
self.logger.info('handling finished, will send to user')
return web.Response(body=json.dumps({'result': resp, 'meta': None}, ensure_ascii=False),
status=200,
Expand Down

0 comments on commit 46e026b

Please sign in to comment.