Commit 544c9458 by 陈森彬

添加master 机器的redis

parent 53597985
Showing with 18 additions and 4 deletions
...@@ -27,6 +27,7 @@ redirect_uri = 'https://bigdata.ichunt.com/digikey_auth.php' ...@@ -27,6 +27,7 @@ redirect_uri = 'https://bigdata.ichunt.com/digikey_auth.php'
# 对接digikey的api的token不放在master而放在这台机器上 # 对接digikey的api的token不放在master而放在这台机器上
apidigikey_ip = "172.18.137.38" apidigikey_ip = "172.18.137.38"
master_redis_ip = "127.0.0.1"
psd = 'icDb29mLy2s' psd = 'icDb29mLy2s'
...@@ -41,6 +42,8 @@ class DGTokenCrawler(token_lib.BaseTokenCrawler): ...@@ -41,6 +42,8 @@ class DGTokenCrawler(token_lib.BaseTokenCrawler):
self.redirect_uri = 'https://bigdata.ichunt.com/digikey_auth.php' self.redirect_uri = 'https://bigdata.ichunt.com/digikey_auth.php'
self._pool = redis.ConnectionPool(host=apidigikey_ip, port=6379, db=0, password=psd) self._pool = redis.ConnectionPool(host=apidigikey_ip, port=6379, db=0, password=psd)
self._redis = redis.Redis(connection_pool=self._pool) self._redis = redis.Redis(connection_pool=self._pool)
self._pool2 = redis.ConnectionPool(host=master_redis_ip, port=6379, db=0, password=psd)
self._redis2 = redis.Redis(connection_pool=self._pool)
self.refresh_token_url = "http://127.0.0.1:8721/refresh" self.refresh_token_url = "http://127.0.0.1:8721/refresh"
def get_params_list(self): def get_params_list(self):
...@@ -51,10 +54,13 @@ class DGTokenCrawler(token_lib.BaseTokenCrawler): ...@@ -51,10 +54,13 @@ class DGTokenCrawler(token_lib.BaseTokenCrawler):
token_json = self.get_token_by_refresh_token() token_json = self.get_token_by_refresh_token()
if not token_json.get('access_token', ''): if not token_json.get('access_token', ''):
dd_send_msg('digikey自动登录同步token') dd_send_msg('digikey自动登录同步token')
resp = requests.get(self.refresh_token_url, timeout=30).json() resp_data = self.get_token_json()
if resp['status'] == 500: if resp_data == False:
raise Exception(resp['msg']) mgs = "digikey 刷新token失败,请手动获取"
token_json = resp['data'] dd_send_msg(mgs)
self.logger.error(mgs)
raise Exception(mgs)
token_json = resp_data['data']
access_token, refresh_token = token_json['access_token'], token_json['refresh_token'] access_token, refresh_token = token_json['access_token'], token_json['refresh_token']
apidigikey_log.info(access_token) apidigikey_log.info(access_token)
apidigikey_log.info(refresh_token) apidigikey_log.info(refresh_token)
...@@ -63,6 +69,13 @@ class DGTokenCrawler(token_lib.BaseTokenCrawler): ...@@ -63,6 +69,13 @@ class DGTokenCrawler(token_lib.BaseTokenCrawler):
dd_send_msg('digikey token同步失败:' + traceback.format_exc()) dd_send_msg('digikey token同步失败:' + traceback.format_exc())
self.logger.error(traceback.format_exc()) self.logger.error(traceback.format_exc())
@retry(tries=5, delay=30)
def get_token_json(self):
resp = requests.get(self.refresh_token_url, timeout=30)
if resp.status_code == 500:
return False
return resp.json()
def get_token(self): def get_token(self):
# url="https://api.digikey.com/v1/oauth2/authorize?response_type=code&client_id=9zwA2tsTFpKURpMIj5VXGK3eoPWLIGgh&redirect_uri=https://bigdata.ichunt.com/digikey_auth.php" # url="https://api.digikey.com/v1/oauth2/authorize?response_type=code&client_id=9zwA2tsTFpKURpMIj5VXGK3eoPWLIGgh&redirect_uri=https://bigdata.ichunt.com/digikey_auth.php"
...@@ -98,4 +111,5 @@ class DGTokenCrawler(token_lib.BaseTokenCrawler): ...@@ -98,4 +111,5 @@ class DGTokenCrawler(token_lib.BaseTokenCrawler):
access_token, refresh_token = self.collect_token() access_token, refresh_token = self.collect_token()
self._redis.set(self.token_key, access_token) self._redis.set(self.token_key, access_token)
self._redis2.set(self.token_key, access_token)
self._redis.set(self.refresh_token_key, refresh_token) self._redis.set(self.refresh_token_key, refresh_token)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment