Commit 115496a1 authored by Ivar Refsdal's avatar Ivar Refsdal

Better logging

parent 5730c9c3
......@@ -4,4 +4,4 @@ set -ex
docker build --tag=docker.nsd.no/programvareutvikling/python-file-submission-poc .
docker run --memory="100M" --publish=8090:8090 docker.nsd.no/programvareutvikling/python-file-submission-poc
docker run -it --memory="100M" --publish=8090:8090 docker.nsd.no/programvareutvikling/python-file-submission-poc
......@@ -17,20 +17,23 @@ app = flask.Flask(__name__)
@app.route('/', defaults={'path': ''}, methods = ['POST'])
@app.route('/<path:path>', methods = ['POST'])
def hello(path):
app.logger.info('new request')
def custom_stream_factory(total_content_length, filename, content_type, content_length=None):
tmpfile = tempfile.NamedTemporaryFile('wb+')
tmpfile = tempfile.NamedTemporaryFile('wb+', prefix='flaskapp')
app.logger.info("start receiving file ... filename => " + str(tmpfile.name))
return tmpfile
ms = measure_spent_time()
stream,form,files = werkzeug.formparser.parse_form_data(flask.request.environ, stream_factory=custom_stream_factory)
total_size = 0
for fil in files.values():
print("saved form name", fil.name, "submitted as", fil.filename, "to temporary file", fil.stream.name)
app.logger.info(" ".join(["saved form name", fil.name, "submitted as", fil.filename, "to temporary file", fil.stream.name]))
total_size += os.path.getsize(fil.stream.name)
mb_per_s = "%.1f" % ((total_size / (1024.0*1024.0)) / ((1.0+ms(raw=True))/1000.0))
print("handling POST request, spent", ms(), "ms.", mb_per_s, "MB/s.", "Number of files:", len(files.values()))
app.logger.info(" ".join([str(x) for x in ["handling POST request, spent", ms(), "ms.", mb_per_s, "MB/s.", "Number of files:", len(files.values())]]))
process = psutil.Process(os.getpid())
print("memory usage: %.1f MiB" % (process.memory_info().rss / (1024.0*1024.0)))
app.logger.info("memory usage: %.1f MiB" % (process.memory_info().rss / (1024.0*1024.0)))
return "Hello World!"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment