@@ -25,29 +25,43 @@ def check_rate(self, value, path):
25
25
rate_expression = value [value .find ("(" ) + 1 : value .find (")" )]
26
26
27
27
if not rate_expression :
28
- matches .append (
29
- RuleMatch (path , "Rate value of ScheduleExpression cannot be empty" )
30
- )
31
- else :
32
- # Rate format: rate(Value Unit)
33
- items = rate_expression .split (" " )
34
-
35
- if len (items ) != 2 :
36
- message = "Rate expression must contain 2 elements (Value Unit), rate contains {} elements"
37
- matches .append (RuleMatch (path , message .format (len (items ))))
38
- else :
39
- # Check the Value
40
- if not items [0 ].isdigit ():
41
- message = "Rate Value ({}) should be of type Integer."
42
- extra_args = {
43
- "actual_type" : type (items [0 ]).__name__ ,
44
- "expected_type" : int .__name__ ,
45
- }
46
- matches .append (
47
- RuleMatch (path , message .format (items [0 ]), ** extra_args )
48
- )
28
+ return [RuleMatch (path , "Rate value of ScheduleExpression cannot be empty" )]
29
+
30
+ # Rate format: rate(Value Unit)
31
+ items = rate_expression .split (" " )
32
+
33
+ if len (items ) != 2 :
34
+ message = "Rate expression must contain 2 elements (Value Unit), rate contains {} elements"
35
+ matches .append (RuleMatch (path , message .format (len (items ))))
36
+ return [RuleMatch (path , message .format (len (items )))]
37
+
38
+ # Check the Value
39
+ if not items [0 ].isdigit ():
40
+ message = "Rate Value ({}) should be of type Integer."
41
+ extra_args = {
42
+ "actual_type" : type (items [0 ]).__name__ ,
43
+ "expected_type" : int .__name__ ,
44
+ }
45
+ return [RuleMatch (path , message .format (items [0 ]), ** extra_args )]
46
+
47
+ if float (items [0 ]) <= 0 :
48
+ return [
49
+ RuleMatch (path , f"Rate Value { items [0 ]!r} should be greater than 0." )
50
+ ]
51
+
52
+ if float (items [0 ]) <= 1 :
53
+ valid_periods = ["minute" , "hour" , "day" ]
54
+ elif float (items [0 ]) > 1 :
55
+ valid_periods = ["minutes" , "hours" , "days" ]
56
+ # Check the Unit
57
+ if items [1 ] not in valid_periods :
58
+ return [
59
+ RuleMatch (
60
+ path , f"Rate Unit { items [1 ]!r} should be one of { valid_periods !r} ."
61
+ )
62
+ ]
49
63
50
- return matches
64
+ return []
51
65
52
66
def check_cron (self , value , path ):
53
67
"""Check Cron configuration"""
0 commit comments