Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LOFAR
Manage
Activity
Members
Labels
Plan
Issues
Wiki
Jira issues
Open Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Insights
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
RadioObservatory
LOFAR
Commits
1c7f0fbb
Commit
1c7f0fbb
authored
7 months ago
by
Jorrit Schaap
Browse files
Options
Downloads
Patches
Plain Diff
minor patches
parent
90188a24
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
SAS/TMSS/backend/services/windmill_standstill/lib/windmill_standstill.py
+5
-4
5 additions, 4 deletions
...d/services/windmill_standstill/lib/windmill_standstill.py
with
5 additions
and
4 deletions
SAS/TMSS/backend/services/windmill_standstill/lib/windmill_standstill.py
+
5
−
4
View file @
1c7f0fbb
...
@@ -58,6 +58,7 @@ class TMSSWindmillStandstillEventMessageHandler(TMSSEventMessageHandler):
...
@@ -58,6 +58,7 @@ class TMSSWindmillStandstillEventMessageHandler(TMSSEventMessageHandler):
self
.
client_id
=
client_id
self
.
client_id
=
client_id
self
.
client_secret
=
client_secret
self
.
client_secret
=
client_secret
self
.
access_token_expiration_date
=
datetime
.
min
self
.
access_token_expiration_date
=
datetime
.
min
self
.
access_token
=
None
def
start_handling
(
self
):
def
start_handling
(
self
):
self
.
refresh_access_token
()
self
.
refresh_access_token
()
...
@@ -80,7 +81,7 @@ class TMSSWindmillStandstillEventMessageHandler(TMSSEventMessageHandler):
...
@@ -80,7 +81,7 @@ class TMSSWindmillStandstillEventMessageHandler(TMSSEventMessageHandler):
"
client_id
"
:
self
.
client_id
,
"
client_id
"
:
self
.
client_id
,
"
client_secret
"
:
self
.
client_secret
})
"
client_secret
"
:
self
.
client_secret
})
except
Exception
as
e
:
except
Exception
as
e
:
logger
.
e
rror
(
"
could not refresh access token: %s
"
,
str
(
e
))
logger
.
e
xception
(
"
could not refresh access token: %s
"
,
str
(
e
))
try
:
try
:
json_response
=
response
.
json
()
json_response
=
response
.
json
()
...
@@ -88,10 +89,11 @@ class TMSSWindmillStandstillEventMessageHandler(TMSSEventMessageHandler):
...
@@ -88,10 +89,11 @@ class TMSSWindmillStandstillEventMessageHandler(TMSSEventMessageHandler):
self
.
access_token_expiration_date
=
datetime
.
utcnow
()
+
timedelta
(
seconds
=
json_response
[
'
expires_in
'
]
-
10
)
self
.
access_token_expiration_date
=
datetime
.
utcnow
()
+
timedelta
(
seconds
=
json_response
[
'
expires_in
'
]
-
10
)
logger
.
info
(
'
new token valid till %s
'
%
self
.
access_token_expiration_date
.
isoformat
())
logger
.
info
(
'
new token valid till %s
'
%
self
.
access_token_expiration_date
.
isoformat
())
except
Exception
as
e
:
except
Exception
as
e
:
logger
.
e
rror
(
"
could not refresh access token: http_status_code=%s error: %s
"
,
response
.
status_code
,
str
(
e
))
logger
.
e
xception
(
"
could not refresh access token: http_status_code=%s error: %s
"
,
response
.
status_code
,
str
(
e
))
def
get_api_path_as_json
(
self
,
path
):
def
get_api_path_as_json
(
self
,
path
):
if
datetime
.
utcnow
()
>=
self
.
access_token_expiration_date
:
logger
.
info
(
'
fetching %s...
'
,
path
)
if
datetime
.
utcnow
()
>=
self
.
access_token_expiration_date
or
self
.
access_token
is
None
:
self
.
refresh_access_token
()
self
.
refresh_access_token
()
headers
=
{
"
Authorization
"
:
"
Bearer
"
+
self
.
access_token
}
headers
=
{
"
Authorization
"
:
"
Bearer
"
+
self
.
access_token
}
response
=
requests
.
get
(
self
.
windmill_api_url
+
path
,
headers
=
headers
)
response
=
requests
.
get
(
self
.
windmill_api_url
+
path
,
headers
=
headers
)
...
@@ -126,7 +128,6 @@ class TMSSWindmillStandstillEventMessageHandler(TMSSEventMessageHandler):
...
@@ -126,7 +128,6 @@ class TMSSWindmillStandstillEventMessageHandler(TMSSEventMessageHandler):
path
+=
'
?
'
if
path
.
endswith
(
'
/
'
)
else
'
&
'
path
+=
'
?
'
if
path
.
endswith
(
'
/
'
)
else
'
&
'
path
+=
'
till
'
+
scheduled_start_time_before
.
isoformat
()
path
+=
'
till
'
+
scheduled_start_time_before
.
isoformat
()
logger
.
info
(
'
fetching %s...
'
)
response
=
self
.
get_api_path_as_json
(
path
)
response
=
self
.
get_api_path_as_json
(
path
)
return
response
[
'
blocks
'
]
return
response
[
'
blocks
'
]
...
...
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