def post_stats(request, response, data):
es_url_template = getattr(settings, 'CAVALRY_ELASTICSEARCH_URL_TEMPLATE', None)
if not es_url_template:
return
payload = build_payload(data, request, response)
es_url = es_url_template.format_map(
dict(
payload,
ymd=datetime.utcnow().strftime('%Y-%m-%d'),
),
)
body = force_bytes(json.dumps(payload, cls=PayloadJSONEncoder))
try:
resp = sess.post(es_url, data=body, headers={'Content-Type': 'application/json'}, timeout=0.5)
if resp.status_code != 201:
log.warning('Unable to post data to %s (error %s): %s', es_url, resp.status_code, resp.text)
except Exception as e:
log.warning('Unable to post data to %s: %s', es_url, e)
评论列表
文章目录