FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
feast/sdk/python/feast/wait.py at v0.60.0 · feast-dev/feast · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
feast-dev
/
feast
Public
Notifications
You must be signed in to change notification settings
Fork
1.4k
Star
7.2k
Code
Issues
215
Pull requests
190
Discussions
Actions
Security and quality
1
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
feast
/
sdk
/
python
/
feast
/
wait.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
55 lines (49 loc) · 2.23 KB
Breadcrumbs
feast
/
sdk
/
python
/
feast
/
wait.py
Copy path
File metadata and controls
55 lines (49 loc) · 2.23 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# Copyright 2019 The Feast Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import
time
from
typing
import
Any
,
Callable
,
Optional
,
Tuple
from
feast
.
constants
import
MAX_WAIT_INTERVAL
def
wait_retry_backoff
(
retry_fn
:
Callable
[[],
Tuple
[
Any
,
bool
]],
timeout_secs
:
int
=
0
,
timeout_msg
:
Optional
[
str
]
=
"Timeout while waiting for retry_fn() to return True"
,
max_interval_secs
:
int
=
int
(
MAX_WAIT_INTERVAL
),
)
->
Any
:
"""
Repeatedly try calling given retry_fn until it returns a True boolean success flag.
Waits with a exponential backoff between retries until timeout when it throws TimeoutError.
Args:
retry_fn: Callable that returns a result and a boolean success flag.
timeout_secs: timeout in seconds to give up retrying and throw TimeoutError,
or 0 to retry perpetually.
timeout_msg: Message to use when throwing TimeoutError.
max_interval_secs: max wait in seconds to wait between retries.
Returns:
Returned Result from retry_fn() if success flag is True.
"""
wait_secs
,
elapsed_secs
=
1.0
,
0.0
result
,
is_success
=
retry_fn
()
wait_begin
=
time
.
time
()
while
not
is_success
and
(
elapsed_secs
<=
timeout_secs
or
timeout_secs
==
0
):
# back off wait duration exponentially, capped at MAX_WAIT_INTERVAL_SEC
elapsed_secs
=
time
.
time
()
-
wait_begin
till_timeout_secs
=
timeout_secs
-
elapsed_secs
wait_secs
=
min
(
wait_secs
*
2
,
max_interval_secs
,
till_timeout_secs
)
time
.
sleep
(
wait_secs
)
# retry call
result
,
is_success
=
retry_fn
()
elapsed_secs
=
time
.
time
()
-
wait_begin
if
not
is_success
and
elapsed_secs
>
timeout_secs
:
raise
TimeoutError
(
timeout_msg
)
return
result
Back
|
FazBrowse Home
|
New Git URL