BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
99043d24
Unverified
Commit
99043d24
authored
Dec 16, 2017
by
Matija Čupić
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add lease to CheckGcpProjectBillingWorker
parent
78f85f3f
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
0 deletions
+29
-0
check_gcp_project_billing_worker.rb
app/workers/check_gcp_project_billing_worker.rb
+11
-0
check_gcp_project_billing_worker_spec.rb
spec/workers/check_gcp_project_billing_worker_spec.rb
+18
-0
No files found.
app/workers/check_gcp_project_billing_worker.rb
View file @
99043d24
class
CheckGcpProjectBillingWorker
class
CheckGcpProjectBillingWorker
include
ApplicationWorker
include
ApplicationWorker
LEASE_TIMEOUT
=
1
.
minute
.
to_i
def
self
.
redis_shared_state_key_for
(
token
)
def
self
.
redis_shared_state_key_for
(
token
)
"gitlab:gcp:
#{
token
}
:billing_enabled"
"gitlab:gcp:
#{
token
}
:billing_enabled"
end
end
def
perform
(
token
)
def
perform
(
token
)
return
unless
token
return
unless
token
return
unless
try_obtain_lease_for
(
token
)
billing_enabled
=
CheckGcpProjectBillingService
.
new
.
execute
(
token
)
billing_enabled
=
CheckGcpProjectBillingService
.
new
.
execute
(
token
)
Gitlab
::
Redis
::
SharedState
.
with
do
|
redis
|
Gitlab
::
Redis
::
SharedState
.
with
do
|
redis
|
redis
.
set
(
self
.
class
.
redis_shared_state_key_for
(
token
),
billing_enabled
)
redis
.
set
(
self
.
class
.
redis_shared_state_key_for
(
token
),
billing_enabled
)
end
end
end
end
private
def
try_obtain_lease_for
(
token
)
Gitlab
::
ExclusiveLease
.
new
(
"check_gcp_project_billing_worker:
#{
token
}
"
,
timeout:
LEASE_TIMEOUT
)
.
try_obtain
end
end
end
spec/workers/check_gcp_project_billing_worker_spec.rb
View file @
99043d24
...
@@ -5,6 +5,11 @@ describe CheckGcpProjectBillingWorker do
...
@@ -5,6 +5,11 @@ describe CheckGcpProjectBillingWorker do
let
(
:token
)
{
'bogustoken'
}
let
(
:token
)
{
'bogustoken'
}
subject
{
described_class
.
new
.
perform
(
token
)
}
subject
{
described_class
.
new
.
perform
(
token
)
}
context
'when there is no lease'
do
before
do
allow_any_instance_of
(
CheckGcpProjectBillingWorker
).
to
receive
(
:try_obtain_lease_for
).
and_return
(
'randomuuid'
)
end
it
'calls the service'
do
it
'calls the service'
do
expect
(
CheckGcpProjectBillingService
).
to
receive_message_chain
(
:new
,
:execute
)
expect
(
CheckGcpProjectBillingService
).
to
receive_message_chain
(
:new
,
:execute
)
...
@@ -21,4 +26,17 @@ describe CheckGcpProjectBillingWorker do
...
@@ -21,4 +26,17 @@ describe CheckGcpProjectBillingWorker do
subject
subject
end
end
end
end
context
'when there is a lease'
do
before
do
allow_any_instance_of
(
CheckGcpProjectBillingWorker
).
to
receive
(
:try_obtain_lease_for
).
and_return
(
false
)
end
it
'does not call the service'
do
expect
(
CheckGcpProjectBillingService
).
not_to
receive
(
:new
)
subject
end
end
end
end
end
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