Kaynağa Gözat

更新天气处理频率

yf_yzl 2 yıl önce
ebeveyn
işleme
6027110aec
1 değiştirilmiş dosya ile 3 ekleme ve 2 silme
  1. 3 2
      crond_script/crond_weather.py

+ 3 - 2
crond_script/crond_weather.py

@@ -7,6 +7,7 @@ from weather import all_city
 import logging
 import django
 import time
+import random
 BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
 sys.path.append(BASE_DIR)
 os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'bigdataAPI.settings')
@@ -88,7 +89,7 @@ def main():
                 day_obj.save()
         except Exception as e:
             logging.warning(f"cityid {day_obj.cityid}  error {e} {today_response.text}")
-        time.sleep(2)
+        time.sleep(random.randint(1, 5))
     logging.warning("over today ...")
     logging.warning("up server day ...")
     server_days = ServerDayData.objects.all()
@@ -102,7 +103,7 @@ def main():
                 server_day_obj.save()
         except Exception as e:
             logging.warning(f"cityid {server_day_obj.cityid}  error {e} {today_response.text}")
-        time.sleep(2)
+        time.sleep(random.randint(1, 5))
     logging.warning("over server day ...")
 
     """