Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
spark
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cs525-sp18-g07
spark
Commits
9bf24e1d
Commit
9bf24e1d
authored
12 years ago
by
Holden Karau
Browse files
Options
Downloads
Patches
Plain Diff
Just use a loop for retries
parent
ff2130a0
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
ec2/retry_decorator.py
+0
-44
0 additions, 44 deletions
ec2/retry_decorator.py
ec2/spark_ec2.py
+17
-6
17 additions, 6 deletions
ec2/spark_ec2.py
with
17 additions
and
50 deletions
ec2/retry_decorator.py
deleted
100644 → 0
+
0
−
44
View file @
ff2130a0
import
time
from
functools
import
wraps
def
retry
(
ExceptionToCheck
,
tries
=
4
,
delay
=
3
,
backoff
=
2
,
logger
=
None
):
"""
Retry calling the decorated function using an exponential backoff.
http://www.saltycrane.com/blog/2009/11/trying-out-retry-decorator-python/
original from: http://wiki.python.org/moin/PythonDecoratorLibrary#Retry
:param ExceptionToCheck: the exception to check. may be a tuple of
exceptions to check
:type ExceptionToCheck: Exception or tuple
:param tries: number of times to try (not retry) before giving up
:type tries: int
:param delay: initial delay between retries in seconds
:type delay: int
:param backoff: backoff multiplier e.g. value of 2 will double the delay
each retry
:type backoff: int
:param logger: logger to use. If None, print
:type logger: logging.Logger instance
"""
def
deco_retry
(
f
):
@wraps
(
f
)
def
f_retry
(
*
args
,
**
kwargs
):
mtries
,
mdelay
=
tries
,
delay
while
mtries
>
1
:
try
:
return
f
(
*
args
,
**
kwargs
)
except
ExceptionToCheck
,
e
:
msg
=
"
%s, Retrying in %d seconds...
"
%
(
str
(
e
),
mdelay
)
if
logger
:
logger
.
warning
(
msg
)
else
:
print
msg
time
.
sleep
(
mdelay
)
mtries
-=
1
mdelay
*=
backoff
return
f
(
*
args
,
**
kwargs
)
return
f_retry
# true decorator
return
deco_retry
This diff is collapsed.
Click to expand it.
ec2/spark_ec2.py
+
17
−
6
View file @
9bf24e1d
...
...
@@ -22,7 +22,6 @@ from __future__ import with_statement
import
logging
import
os
import
random
from
retry_decorator
import
retry
import
shutil
import
subprocess
import
sys
...
...
@@ -541,12 +540,24 @@ def scp(host, opts, local_file, dest_file):
(
opts
.
identity_file
,
local_file
,
opts
.
user
,
host
,
dest_file
),
shell
=
True
)
# Run a command on a host through ssh,
throwing an exception if ssh fail
s
@retry
(
subprocess
.
CalledProcessError
,
tries
=
3
,
delay
=
30
)
# Run a command on a host through ssh,
retrying up to two time
s
# and then throwing an exception if ssh continues to fail.
def
ssh
(
host
,
opts
,
command
):
subprocess
.
check_call
(
"
ssh -t -o StrictHostKeyChecking=no -i %s %s@%s
'
%s
'"
%
(
opts
.
identity_file
,
opts
.
user
,
host
,
command
),
shell
=
True
)
tries
=
0
while
True
:
try
:
return
subprocess
.
check_call
(
"
ssh -t -o StrictHostKeyChecking=no -i %s %s@%s
'
%s
'"
%
(
opts
.
identity_file
,
opts
.
user
,
host
,
command
),
shell
=
True
)
except
subprocess
.
CalledProcessError
as
e
:
if
(
tries
>
2
):
raise
e
print
"
Error connecting to host {0}, sleeping 30
"
.
format
(
e
)
time
.
sleep
(
30
)
tries
=
tries
+
1
# Gets a list of zones to launch instances in
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment