Explorar el Código

修改celery创建cron任务day_of_week参数

locky hace 1 año
padre
commit
adc4759750

+ 7 - 4
Controller/SensorGateway/SmartSceneController.py

@@ -1365,10 +1365,12 @@ class SmartSceneView(View):
     def int_to_weeks(repeat, is_next_day=False):
         """
         十进制转星期周期
-        @param repeat: 星期周期二进制的十进制数,低到高位表示周一到周日,如64 -> 100 0000 -> 周日
+        @param repeat: 星期周期的十进制数,如127 -> 每天 -> 0,1,2,3,4,5,6或*
         @param is_next_day: 是否隔天
         @return: weeks
         """
+        if repeat == 127:
+            return '*'
         # 十进制转为7位的二进制并倒序
         bin_str = bin(repeat)[2:].zfill(7)[::-1]
         # 生成星期周期字符串
@@ -1376,9 +1378,10 @@ class SmartSceneView(View):
         next_day = 1 if is_next_day else 0
         for i, bit in enumerate(bin_str):
             if bit == '1':
-                week = i + 1 + next_day
-                if week == 8:
-                    week = 1
+                # 7 -> 0
+                week = i + next_day
+                if week == 7:
+                    week = 0
                 weeks += str(week) + ','
         # 删除最后一个逗号并返回结果
         return weeks[:-1]

+ 1 - 1
Object/CeleryBeatObject.py

@@ -76,7 +76,7 @@ class CeleryBeatObj:
         @param task: 任务函数
         @param minute: 分
         @param hour: 时
-        @param day_of_week: 周,1-7对应周一到周日,也可写mon,tue,wed,thu,fri,sat,sun
+        @param day_of_week: 周,0-6对应周日到周六,也可写sun,mon,tue,wed,thu,fri,sat
         @param day_of_month: 月
         @param month_of_year: 年
         @param args: 参数