15
15
16
16
DEFAULT_INSTANCE_RETRY_DURATION = 60 * 60 * 24 # 24h
17
17
18
+ DEFAULT_STOP_DURATION = 300
19
+
18
20
19
21
class SpotPolicy (str , Enum ):
20
22
SPOT = "spot"
@@ -38,16 +40,27 @@ def parse_duration(v: Optional[Union[int, str]]) -> Optional[int]:
38
40
return Duration .parse (v )
39
41
40
42
41
- def parse_max_duration (v : Optional [Union [int , str ]]) -> Optional [Union [str , int ]]:
42
- # TODO: [Andrey] Not sure this works (see `parse_idle_duration`)
43
- if v == "off" :
44
- return v
43
+ def parse_max_duration (v : Optional [Union [int , str , bool ]]) -> Optional [Union [str , int , bool ]]:
44
+ return parse_off_duration (v )
45
+
46
+
47
+ def parse_stop_duration (v : Optional [Union [int , str , bool ]]) -> Optional [Union [str , int , bool ]]:
48
+ return parse_off_duration (v )
49
+
50
+
51
+ def parse_off_duration (v : Optional [Union [int , str , bool ]]) -> Optional [Union [str , int , bool ]]:
52
+ if v == "off" or v is False :
53
+ return "off"
54
+ if v is True :
55
+ return None
45
56
return parse_duration (v )
46
57
47
58
48
- def parse_idle_duration (v : Optional [Union [int , str ]]) -> Optional [Union [str , int ]]:
59
+ def parse_idle_duration (v : Optional [Union [int , str , bool ]]) -> Optional [Union [str , int , bool ]]:
49
60
if v is False :
50
61
return - 1
62
+ if v is True :
63
+ return None
51
64
return parse_duration (v )
52
65
53
66
@@ -136,9 +149,24 @@ class ProfileParams(CoreModel):
136
149
Field (description = "The policy for resubmitting the run. Defaults to `false`" ),
137
150
]
138
151
max_duration : Annotated [
139
- Optional [Union [Literal ["off" ], str , int ]],
152
+ Optional [Union [Literal ["off" ], str , int , bool ]],
140
153
Field (
141
- description = "The maximum duration of a run (e.g., `2h`, `1d`, etc). After it elapses, the run is forced to stop. Defaults to `off`"
154
+ description = (
155
+ "The maximum duration of a run (e.g., `2h`, `1d`, etc)."
156
+ " After it elapses, the run is automatically stopped."
157
+ " Use `off` for unlimited duration. Defaults to `off`"
158
+ )
159
+ ),
160
+ ]
161
+ stop_duration : Annotated [
162
+ Optional [Union [Literal ["off" ], str , int , bool ]],
163
+ Field (
164
+ description = (
165
+ "The maximum duration of a run gracefull stopping."
166
+ " After it elapses, the run is automatically forced stopped."
167
+ " This includes force detaching volumes used by the run."
168
+ " Use `off` for unlimited duration. Defaults to `5m`"
169
+ )
142
170
),
143
171
]
144
172
max_price : Annotated [
@@ -152,9 +180,12 @@ class ProfileParams(CoreModel):
152
180
),
153
181
]
154
182
idle_duration : Annotated [
155
- Optional [Union [Literal ["off" ], str , int ]],
183
+ Optional [Union [Literal ["off" ], str , int , bool ]],
156
184
Field (
157
- description = "Time to wait before terminating idle instances. Defaults to `5m` for runs and `3d` for fleets. Use `off` for unlimited duration"
185
+ description = (
186
+ "Time to wait before terminating idle instances."
187
+ " Defaults to `5m` for runs and `3d` for fleets. Use `off` for unlimited duration"
188
+ )
158
189
),
159
190
]
160
191
# Deprecated:
@@ -180,6 +211,9 @@ class ProfileParams(CoreModel):
180
211
_validate_max_duration = validator ("max_duration" , pre = True , allow_reuse = True )(
181
212
parse_max_duration
182
213
)
214
+ _validate_stop_duration = validator ("stop_duration" , pre = True , allow_reuse = True )(
215
+ parse_stop_duration
216
+ )
183
217
_validate_termination_idle_time = validator (
184
218
"termination_idle_time" , pre = True , allow_reuse = True
185
219
)(parse_duration )
0 commit comments