def on_post(self, req, resp, doc_index):
try:
raw_json = req.stream.read()
except Exception as ex:
raise falcon.HTTPError(falcon.HTTP_400,
'Error',
ex.message)
try:
result_json = json.loads(raw_json, encoding='utf-8')
except ValueError:
raise falcon.HTTPError(falcon.HTTP_400,
'Malformed JSON',
'Could not decode the request body. The JSON was incorrect.')
"""
Enqueueing write request as jobs into document_write queue
and processing them in the background with workers.
"""
q = Queue('document_write', connection=self.db.connection())
job = q.enqueue_call(
func=postDocument, args=(result_json, doc_index), result_ttl=5000
)
LOG.info('POST request ' + str(job.get_id()))
resp.status = falcon.HTTP_202
resp.body = json.dumps(result_json, encoding='utf-8')
# This function handles DELETE reuqests
评论列表
文章目录