From c8da0dddc7e746133a4973437ab2eb69cbd94dce Mon Sep 17 00:00:00 2001 From: codeskyblue Date: Fri, 20 Mar 2020 19:04:41 +0800 Subject: [PATCH] add retry to upload to qiniu --- scripts/requirements.txt | 3 ++- scripts/upload2qiniu.py | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/scripts/requirements.txt b/scripts/requirements.txt index a55428d..6e93b03 100644 --- a/scripts/requirements.txt +++ b/scripts/requirements.txt @@ -1 +1,2 @@ -qiniu~=7.2 \ No newline at end of file +qiniu~=7.2 +retry~=0.9.2 diff --git a/scripts/upload2qiniu.py b/scripts/upload2qiniu.py index 9e99c2b..c3331ca 100644 --- a/scripts/upload2qiniu.py +++ b/scripts/upload2qiniu.py @@ -3,12 +3,13 @@ import argparse import glob import re +import logging import os import qiniu.config from qiniu import Auth, etag, put_file from qiniu import Zone, set_default - +from retry import retry class Qiniu: def __init__(self, access_key, secret_key, bucket_name: str): @@ -17,13 +18,12 @@ def __init__(self, access_key, secret_key, bucket_name: str): self._auth = Auth(access_key, secret_key) self._bucket = bucket_name + @retry(tries=5, delay=0.5, jitter=0.1, logger=logging) def upload_file(self, key, localfile): token = self._auth.upload_token(self._bucket, key) ret, info = put_file(token, key, localfile) - # print(ret) - print(ret) - # assert ret['key'] == key - # assert ret['hash'] == etag(localfile) + assert ret['key'] == key + assert ret['hash'] == etag(localfile) return info