-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement new improved retry logic (#1282)
* Implement improved retry logic * Pretty format retry * Fix test_process_runs * Support new retry for instances * Update docs on retry
- Loading branch information
Showing
21 changed files
with
392 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from typing import Optional | ||
|
||
from dstack._internal.core.models.profiles import DEFAULT_RETRY_DURATION, Profile, RetryEvent | ||
from dstack._internal.core.models.runs import Retry | ||
|
||
|
||
def get_retry(profile: Profile) -> Optional[Retry]: | ||
profile_retry = profile.retry | ||
if profile_retry is None: | ||
# Handle retry_policy before retry was introduced | ||
# TODO: Remove once retry_policy no longer supported | ||
profile_retry_policy = profile.retry_policy | ||
if profile_retry_policy is None: | ||
return None | ||
if not profile_retry_policy.retry: | ||
return None | ||
duration = profile_retry_policy.duration or DEFAULT_RETRY_DURATION | ||
return Retry( | ||
on_events=[RetryEvent.NO_CAPACITY, RetryEvent.INTERRUPTION, RetryEvent.ERROR], | ||
duration=duration, | ||
) | ||
if isinstance(profile_retry, bool): | ||
if profile_retry: | ||
return Retry( | ||
on_events=[RetryEvent.NO_CAPACITY, RetryEvent.INTERRUPTION, RetryEvent.ERROR], | ||
duration=DEFAULT_RETRY_DURATION, | ||
) | ||
return None | ||
profile_retry = profile_retry.copy() | ||
if profile_retry.duration is None: | ||
profile_retry.duration = DEFAULT_RETRY_DURATION | ||
return Retry.parse_obj(profile_retry) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.