Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
638c6162
Commit
638c6162
authored
Oct 06, 2017
by
Shinya Maeda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use utc for time comparision
parent
354e2ef0
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
12 additions
and
7 deletions
+12
-7
app/workers/wait_for_cluster_creation_worker.rb
app/workers/wait_for_cluster_creation_worker.rb
+1
-1
lib/google_api/cloud_platform/client.rb
lib/google_api/cloud_platform/client.rb
+8
-3
spec/lib/google_api/cloud_platform/client_spec.rb
spec/lib/google_api/cloud_platform/client_spec.rb
+2
-2
spec/workers/wait_for_cluster_creation_worker_spec.rb
spec/workers/wait_for_cluster_creation_worker_spec.rb
+1
-1
No files found.
app/workers/wait_for_cluster_creation_worker.rb
View file @
638c6162
...
...
@@ -11,7 +11,7 @@ class WaitForClusterCreationWorker
Ci
::
FetchGcpOperationService
.
new
.
execute
(
cluster
)
do
|
operation
|
case
operation
.
status
when
'RUNNING'
if
TIMEOUT
<
Time
.
zone
.
now
-
operation
.
start_time
.
to_time
if
TIMEOUT
<
Time
.
now
.
utc
-
operation
.
start_time
.
to_time
.
utc
return
cluster
.
make_errored!
(
"Cluster creation time exceeds timeout;
#{
TIMEOUT
}
"
)
end
...
...
lib/google_api/cloud_platform/client.rb
View file @
638c6162
...
...
@@ -5,6 +5,7 @@ module GoogleApi
class
Client
<
GoogleApi
::
Auth
DEFAULT_MACHINE_TYPE
=
'n1-standard-1'
.
freeze
SCOPE
=
'https://www.googleapis.com/auth/cloud-platform'
.
freeze
LEAST_TOKEN_LIFE_TIME
=
10
.
minutes
class
<<
self
def
session_key_for_token
...
...
@@ -25,9 +26,7 @@ module GoogleApi
return
false
unless
expires_at
# Making sure that the token will have been still alive during the cluster creation.
unless
DateTime
.
strptime
(
expires_at
,
'%s'
).
to_time
>
Time
.
now
+
10
.
minutes
return
false
end
return
false
if
token_life_time
(
expires_at
)
<
LEAST_TOKEN_LIFE_TIME
true
end
...
...
@@ -68,6 +67,12 @@ module GoogleApi
m
=
self_link
.
match
(
%r{projects/.*/zones/.*/operations/(.*)}
)
m
[
1
]
if
m
end
private
def
token_life_time
(
expires_at
)
DateTime
.
strptime
(
expires_at
,
'%s'
).
to_time
.
utc
-
Time
.
now
.
utc
end
end
end
end
spec/lib/google_api/cloud_platform/client_spec.rb
View file @
638c6162
...
...
@@ -7,7 +7,7 @@ describe GoogleApi::CloudPlatform::Client do
describe
'#validate_token'
do
subject
{
client
.
validate_token
(
expires_at
)
}
let
(
:expires_at
)
{
1
.
hour
.
since
.
strftime
(
'%s'
)
}
let
(
:expires_at
)
{
1
.
hour
.
since
.
utc
.
strftime
(
'%s'
)
}
context
'when token is nil'
do
let
(
:token
)
{
nil
}
...
...
@@ -26,7 +26,7 @@ describe GoogleApi::CloudPlatform::Client do
end
context
'when expires in 10 minutes'
do
let
(
:expires_at
)
{
5
.
minutes
.
since
.
strftime
(
'%s'
)
}
let
(
:expires_at
)
{
5
.
minutes
.
since
.
utc
.
strftime
(
'%s'
)
}
it
{
is_expected
.
to
be_falsy
}
end
...
...
spec/workers/wait_for_cluster_creation_worker_spec.rb
View file @
638c6162
...
...
@@ -24,7 +24,7 @@ describe WaitForClusterCreationWorker do
context
'when operation timeout'
do
before
do
allow
(
operation
).
to
receive
(
:start_time
).
and_return
(
30
.
minutes
.
ago
)
allow
(
operation
).
to
receive
(
:start_time
).
and_return
(
30
.
minutes
.
ago
.
utc
)
end
it
'sets an error message on cluster'
do
...
...
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