poster.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:django-cavalry 作者: valohai 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号