问题描述
在代码中,我多次调用在远程数据库上执行不同任务的函数, 如果我正在运行一个调用,在某些情况下返回代码为 http 代码 = 202(“接受”), 所以它也需要在“重试”模式下调用其他函数完成的任务,
代码:
class Trg:
def __init__(self,**kwargs):
self.__dict__.update(kwargs)
self.kwargs = kwargs
self.trg_cb_connention = Cluster("http://"+ self._checkIfIP(self.TARGET_CB_DB)+ ":8091",ClusterOptions(PasswordAuthenticator(self.TARGET_USER,self.TARGET_PASSWORD)))
.....
.....
def _ConnectToBucket(self):
try:
bucket = self.trg_cb_connention.bucket(self.trg_bucket_name)
#means bucket exist,otherwise create
return True
except Exception as e:
#bucket not exist,creating
self._CreateBucket()
def _CreateBucket(self):
try:
self.bm = self.trg_cb_connention.buckets()
response = self.bm.create_bucket(CreateBucketSettings(name=self.trg_bucket_name,bucket_type="couchbase",ram_quota_mb=100))
if response.http_status == 202: #acepected
#means "acepected:"
#Now call to function which validate the bucket created
self.retry_call(self._CheckBucketCreated())
else:
print("to check:",response)
def retry_call(function_name,args=None,kwargs=None,retries=300):
pass_on_args = args if args else []
pass_on_kwargs = kwargs if kwargs else {}
for index in range(1,retries+1):
try:
return function_name(*pass_on_args,**pass_on_kwargs)
except Exception as error:
if index == retries:
print("Failed %s attempts at calling: %s",retries,function_name)
raise
else:
print("Failed %d attempt(s) at calling: %s",index,function_name)
print("retrying")
失败原因:
Failed %d attempt(s) at calling: %s 1 MIG_ilceosp089
....
.......
........
retrying
Failed %s attempts at calling: %s 300 MIG_ilceosp089
Error 'Trg' object is not callable
首先,为什么会失败? 第二 - 不确定我是否做得对,我很好奇这种操作的正确方法是什么。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)