Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
synnefo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
itminedu
synnefo
Commits
8de6ff1a
Commit
8de6ff1a
authored
Mar 01, 2013
by
Ilias Tsitsimpis
Committed by
Christos Stavrakakis
Mar 12, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add retry option to AstakosClient
parent
e75c9698
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
24 deletions
+23
-24
snf-astakos-client/astakosclient/__init__.py
snf-astakos-client/astakosclient/__init__.py
+23
-24
No files found.
snf-astakos-client/astakosclient/__init__.py
View file @
8de6ff1a
...
...
@@ -56,13 +56,15 @@ class AstakosClient():
"""AstakosClient Class Implementation"""
# ----------------------------------
def
__init__
(
self
,
token
,
astakos_url
,
use_pool
=
False
,
logger
=
None
):
def
__init__
(
self
,
token
,
astakos_url
,
use_pool
=
False
,
retry
=
0
,
logger
=
None
):
"""Intialize AstakosClient Class
Keyword arguments:
token -- user's token (string)
astakos_url -- i.e https://accounts.example.com (string)
use_pool -- use objpool for http requests (boolean)
retry -- how many time to retry (integer)
logger -- pass a different logger
"""
...
...
@@ -90,6 +92,7 @@ class AstakosClient():
raise
ValueError
(
m
)
# Save token and url
self
.
retry
=
retry
self
.
logger
=
logger
self
.
token
=
token
self
.
netloc
=
p
.
netloc
...
...
@@ -97,6 +100,25 @@ class AstakosClient():
self
.
conn
=
conn
# ----------------------------------
def
retry
(
func
):
def
decorator
(
self
,
*
args
,
**
kwargs
):
attemps
=
0
while
True
:
try
:
return
func
(
self
,
*
args
,
**
kwargs
)
except
AstakosClientException
as
err
:
is_last_attempt
=
attemps
==
self
.
retry
if
is_last_attempt
:
raise
err
if
err
.
status
==
401
or
err
.
status
==
404
:
# In case of Unauthorized response
# or Not Found return immediately
raise
err
attemps
+=
1
return
decorator
# ----------------------------------
@
retry
def
_callAstakos
(
self
,
request_path
,
headers
=
{},
body
=
{},
method
=
"GET"
):
"""Make the actual call to Astakos Service"""
self
.
logger
.
debug
(
...
...
@@ -178,29 +200,6 @@ class AstakosClient():
return
uuid_dict
.
get
(
uuid
)
# A simple retry decorator
def
retry
(
howmany
):
def
decorator
(
func
):
def
f
(
*
args
,
**
kwargs
):
attemps
=
0
while
True
:
try
:
return
func
(
*
args
,
**
kwargs
)
except
Exception
as
e
:
is_last_attempt
=
attemps
==
howmany
-
1
if
is_last_attempt
:
raise
e
if
e
.
args
:
status
=
e
[
0
]
# In case of Unauthorized response
# or Not Found return immediately
if
status
==
401
or
status
==
404
:
raise
e
attemps
+=
1
return
f
return
decorator
# --------------------------------------------------------------------
# Private functions
def
_scheme_to_class
(
scheme
,
use_pool
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment