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
5993cf43
Commit
5993cf43
authored
Aug 26, 2020
by
Mark Chao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update seats in used and owed during cron update
parent
becb7685
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
15 deletions
+41
-15
ee/app/workers/update_max_seats_used_for_gitlab_com_subscriptions_worker.rb
...ate_max_seats_used_for_gitlab_com_subscriptions_worker.rb
+9
-5
ee/spec/workers/update_max_seats_used_for_gitlab_com_subscriptions_worker_spec.rb
...ax_seats_used_for_gitlab_com_subscriptions_worker_spec.rb
+32
-10
No files found.
ee/app/workers/update_max_seats_used_for_gitlab_com_subscriptions_worker.rb
View file @
5993cf43
...
...
@@ -17,16 +17,20 @@ class UpdateMaxSeatsUsedForGitlabComSubscriptionsWorker # rubocop:disable Scalab
subscriptions
.
each
do
|
subscription
|
seats_in_use
=
subscription
.
calculate_seats_in_use
max_seats_used
=
[
subscription
.
max_seats_used
,
seats_in_use
].
max
subscription
.
max_seats_used
=
max_seats_used
seats_owed
=
subscription
.
calculate_seats_owed
next
if
subscription
.
max_seats_used
>=
seats_in_use
tuples
<<
[
subscription
.
id
,
seats_in_use
]
tuples
<<
[
subscription
.
id
,
max_seats_used
,
seats_in_use
,
seats_owed
]
end
if
tuples
.
present?
GitlabSubscription
.
connection
.
execute
<<-
EOF
UPDATE gitlab_subscriptions AS s SET max_seats_used = v.max_seats_used
FROM (VALUES
#{
tuples
.
map
{
|
tuple
|
"(
#{
tuple
.
join
(
', '
)
}
)"
}
.join(', ')}) AS v(id, max_seats_used)
UPDATE gitlab_subscriptions AS s
SET max_seats_used = v.max_seats_used,
seats_in_use = v.seats_in_use,
seats_owed = v.seats_owed
FROM (VALUES
#{
tuples
.
map
{
|
tuple
|
"(
#{
tuple
.
join
(
', '
)
}
)"
}
.join(', ')}) AS v(id, max_seats_used, seats_in_use, seats_owed)
WHERE s.id = v.id
EOF
end
...
...
ee/spec/workers/update_max_seats_used_for_gitlab_com_subscriptions_worker_spec.rb
View file @
5993cf43
...
...
@@ -5,11 +5,11 @@ require 'spec_helper'
RSpec
.
describe
UpdateMaxSeatsUsedForGitlabComSubscriptionsWorker
do
subject
{
described_class
.
new
}
let
!
(
:user
)
{
create
(
:user
)
}
let
!
(
:group
)
{
create
(
:group
)
}
let
!
(
:bronze_plan
)
{
create
(
:bronze_plan
)
}
let
!
(
:early_adopter_plan
)
{
create
(
:early_adopter_plan
)
}
let
!
(
:gitlab_subscription
)
{
create
(
:gitlab_subscription
,
namespace:
group
)
}
let
_it_be
(
:user
)
{
create
(
:user
)
}
let
_it_be
(
:group
)
{
create
(
:group
)
}
let
_it_be
(
:bronze_plan
)
{
create
(
:bronze_plan
)
}
let
_it_be
(
:early_adopter_plan
)
{
create
(
:early_adopter_plan
)
}
let
_it_be
(
:gitlab_subscription
,
refind:
true
)
{
create
(
:gitlab_subscription
,
namespace:
group
,
seats:
1
)
}
let
(
:db_is_read_only
)
{
false
}
let
(
:subscription_attrs
)
{
nil
}
...
...
@@ -56,19 +56,41 @@ RSpec.describe UpdateMaxSeatsUsedForGitlabComSubscriptionsWorker do
include_examples
'keeps original max_seats_used value'
end
context
'with a paid plan'
do
context
'with a paid plan'
,
:aggregate_failures
do
let_it_be
(
:other_user
)
{
create
(
:user
)
}
let_it_be
(
:other_group
)
{
create
(
:group
)
}
let_it_be
(
:other_gitlab_subscription
,
refind:
true
)
{
create
(
:gitlab_subscription
,
namespace:
other_group
,
seats:
1
)
}
before
do
group
.
add_developer
(
other_user
)
other_group
.
add_developer
(
other_user
)
gitlab_subscription
.
update!
(
hosted_plan:
bronze_plan
)
other_gitlab_subscription
.
update!
(
hosted_plan:
bronze_plan
)
end
it
'only updates max_seats_used if active users count is greater than it'
do
expect
{
subject
.
perform
}.
to
change
{
gitlab_subscription
.
reload
.
max_seats_used
}.
to
(
1
)
expect
do
subject
.
perform
gitlab_subscription
.
reload
other_gitlab_subscription
.
reload
end
.
to
change
(
gitlab_subscription
,
:max_seats_used
).
from
(
0
).
to
(
2
)
.
and
change
(
gitlab_subscription
,
:seats_in_use
).
from
(
0
).
to
(
2
)
.
and
change
(
gitlab_subscription
,
:seats_owed
).
from
(
0
).
to
(
1
)
.
and
change
(
other_gitlab_subscription
,
:max_seats_used
).
from
(
0
).
to
(
1
)
.
and
change
(
other_gitlab_subscription
,
:seats_in_use
).
from
(
0
).
to
(
1
)
.
and
not_change
(
other_gitlab_subscription
,
:seats_owed
).
from
(
0
)
end
it
'does not update max_seats_used if active users count is lower than it'
do
gitlab_subscription
.
update_attribute
(
:max_seats_used
,
5
)
expect
{
subject
.
perform
}.
not_to
change
{
gitlab_subscription
.
reload
.
max_seats_used
}
gitlab_subscription
.
update_column
(
:max_seats_used
,
5
)
expect
do
subject
.
perform
gitlab_subscription
.
reload
end
.
to
change
(
gitlab_subscription
,
:seats_in_use
).
from
(
0
).
to
(
2
)
.
and
change
(
gitlab_subscription
,
:seats_owed
).
from
(
0
).
to
(
4
)
.
and
not_change
(
gitlab_subscription
,
:max_seats_used
).
from
(
5
)
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