Skip to content
This repository has been archived by the owner on May 27, 2024. It is now read-only.

Commit

Permalink
add retry to upload to qiniu
Browse files Browse the repository at this point in the history
  • Loading branch information
codeskyblue committed Mar 20, 2020
1 parent a046203 commit c8da0dd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
3 changes: 2 additions & 1 deletion scripts/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
qiniu~=7.2
qiniu~=7.2
retry~=0.9.2
10 changes: 5 additions & 5 deletions scripts/upload2qiniu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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


Expand Down

0 comments on commit c8da0dd

Please sign in to comment.