tasks.py 文件源码

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

项目:toshi-reputation-service 作者: toshiapp 项目源码 文件源码
def do_push(push_url, body, address, signing_key, reviewee_id):

    path = '/' + push_url.split('/', 3)[-1]

    method = 'POST'
    backoff = 5
    retries = 10

    terminate = False
    async with aiohttp.ClientSession() as session:
        while not terminate:
            timestamp = int(time.time())
            signature = sign_request(signing_key, method, path, timestamp, body)

            with aiohttp.Timeout(10):
                async with session.post(push_url,
                                        headers={
                                            'content-type': 'application/json',
                                            TOSHI_SIGNATURE_HEADER: signature,
                                            TOSHI_ID_ADDRESS_HEADER: address,
                                            TOSHI_TIMESTAMP_HEADER: str(timestamp)},
                                        data=body) as response:
                    if response.status == 204 or response.status == 200:
                        terminate = True
                    else:
                        log.error("Error updating user details")
                        log.error("URL: {}".format(push_url))
                        log.error("User Address: {}".format(reviewee_id))
                    retries -= 1
                    if retries <= 0:
                        terminate = True
            await asyncio.sleep(backoff)
            backoff = min(backoff + 5, 30)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号