diff --git a/fir_ser/api/tasks.py b/fir_ser/api/tasks.py index f81fa30..1f04230 100644 --- a/fir_ser/api/tasks.py +++ b/fir_ser/api/tasks.py @@ -13,7 +13,7 @@ from api.models import Apps, DeveloperAppID from api.utils.app.supersignutils import IosUtils, resign_by_app_id_and_developer from api.utils.crontab.ctasks import sync_download_times, auto_clean_upload_tmp_file, auto_delete_ios_mobile_tmp_file, \ auto_check_ios_developer_active -from api.utils.crontab.iproxy import get_best_proxy_ips +from api.utils.crontab.iproxy import get_best_proxy_ips, clean_ip_proxy_infos from api.utils.geetest.geetest_utils import check_bypass_status from api.utils.mp.wechat import sync_wx_access_token from api.utils.storage.caches import MigrateStorageState @@ -79,8 +79,10 @@ def run_resign_task_do(app_id, developer_id, developer_app_id, need_download_pro @app.task def start_api_sever_do_clean(): # 启动服务的时候,同时执行下面操作,主要是修改配置存储的时候,需要执行清理,否则会出问题,如果不修改,则无需执行 + logger.info("clean local storage cache") get_local_storage(clean_cache=True) check_bypass_status() + clean_ip_proxy_infos() @app.task diff --git a/fir_ser/api/utils/crontab/iproxy.py b/fir_ser/api/utils/crontab/iproxy.py index 869ef75..4e96be5 100644 --- a/fir_ser/api/utils/crontab/iproxy.py +++ b/fir_ser/api/utils/crontab/iproxy.py @@ -56,7 +56,7 @@ def get_proxy_ip_from_cache(change_ip=False): if not ip_proxy_result: ip_proxy_result = get_best_proxy_ips() - if change_ip: + if change_ip and ip_proxy_result: try: ip_proxy_result.remove(active_ip_proxy) except Exception as e: @@ -65,7 +65,7 @@ def get_proxy_ip_from_cache(change_ip=False): cache.delete(ip_proxy_store_active_key) cache.set(ip_proxy_store_key, ip_proxy_result, 24 * 60 * 60) - if len(ip_proxy_result) > 0: + if ip_proxy_result and len(ip_proxy_result) > 0: proxy_ip = ip_proxy_result[random.randint(0, 2 if len(ip_proxy_result) > 2 else len(ip_proxy_result) - 1)] proxy_info = { 'http': proxy_ip, @@ -76,3 +76,11 @@ def get_proxy_ip_from_cache(change_ip=False): logger.info(f"make ip proxy cache {proxy_info}") cache.set(ip_proxy_store_active_key, proxy_info, 24 * 60 * 60) return proxy_info + + +def clean_ip_proxy_infos(): + logger.info("clean ip proxy infos") + ip_proxy_store_key = CACHE_KEY_TEMPLATE.get("ip_proxy_store_list_key") + ip_proxy_store_active_key = CACHE_KEY_TEMPLATE.get("ip_proxy_store_active_key") + cache.delete(ip_proxy_store_key) + cache.delete(ip_proxy_store_active_key)