1
1
import os
2
2
from enum import Enum
3
- from typing import Dict , List , Optional , Type , Union
3
+ from typing import Any , Dict , List , Optional , Type , Union
4
4
5
5
from pydantic import BaseModel , root_validator , validator
6
6
@@ -36,35 +36,38 @@ class NotificationsConfig(BaseModel):
36
36
include_output (bool): A flag indicating whether a output should be included in the notification. Default is False.
37
37
"""
38
38
39
- send_to : List [str ]
40
- events : List [NotificationEvent ]
39
+ send_to : List [str ] = []
40
+ events : List [NotificationEvent ] = []
41
41
include_output : bool = False
42
42
43
+ def to_dict (self ):
44
+ return self .dict (exclude_none = True )
45
+
43
46
@validator ("send_to" )
44
- def validate_send_to (cls , send_to ):
45
- if len (send_to ) > 100 :
47
+ def validate_send_to (cls , v ):
48
+ if len (v ) > 100 :
46
49
raise ValueError ("Too many 'Send to' addressee identifiers. Maximum allowed is 100." )
47
- return send_to
50
+ return v
48
51
49
52
@validator ("send_to" , each_item = True )
50
- def validate_send_to_items (cls , send_to_item ):
51
- if len (send_to_item ) > 100 :
53
+ def validate_send_to_items (cls , v ):
54
+ if len (v ) > 100 :
52
55
raise ValueError (
53
56
"Each 'Send to' addressee identifier should be at most 100 characters long."
54
57
)
55
- return send_to_item
58
+ return v
56
59
57
60
@validator ("events" )
58
- def validate_events (cls , send_to ):
59
- if len (send_to ) > 100 :
61
+ def validate_events (cls , v ):
62
+ if len (v ) > 100 :
60
63
raise ValueError ("Too many notification events. Maximum allowed is 100." )
61
- return send_to
64
+ return v
62
65
63
66
@validator ("events" , each_item = True )
64
- def validate_events_items (cls , events_item ):
65
- if len (events_item .value ) > 100 :
67
+ def validate_events_items (cls , v ):
68
+ if len (v .value ) > 100 :
66
69
raise ValueError ("Each notification event should be at most 100 characters long." )
67
- return events_item
70
+ return v
68
71
69
72
70
73
class RuntimeEnvironment (BaseModel ):
@@ -82,8 +85,8 @@ class RuntimeEnvironment(BaseModel):
82
85
compute_types : Optional [List [str ]]
83
86
default_compute_type : Optional [str ] # Should be a member of the compute_types list
84
87
utc_only : Optional [bool ]
85
- notifications_enabled : bool = False
86
- notification_events : List [Type [NotificationEvent ]] = []
88
+ notifications_enabled : bool = True
89
+ notification_events : List [Type [NotificationEvent ]] = [e for e in NotificationEvent ]
87
90
88
91
def __str__ (self ):
89
92
return self .json ()
@@ -152,6 +155,12 @@ def compute_input_filename(cls, values) -> Dict:
152
155
153
156
return values
154
157
158
+ @validator ("notifications_config" , pre = True , always = True )
159
+ def convert_notifications_config (cls , v ):
160
+ if isinstance (v , NotificationsConfig ):
161
+ return v .to_dict ()
162
+ return v
163
+
155
164
156
165
class JobFile (BaseModel ):
157
166
"""This model is used to describe the display value,
0 commit comments