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
599ba42d
Commit
599ba42d
authored
Sep 28, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement active pipelines limit
parent
7696a43e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
149 additions
and
0 deletions
+149
-0
ee/lib/ee/gitlab/ci/limit.rb
ee/lib/ee/gitlab/ci/limit.rb
+25
-0
ee/lib/ee/gitlab/ci/pipeline/quota/activity.rb
ee/lib/ee/gitlab/ci/pipeline/quota/activity.rb
+49
-0
spec/ee/spec/lib/gitlab/ci/pipeline/quota/activity_spec.rb
spec/ee/spec/lib/gitlab/ci/pipeline/quota/activity_spec.rb
+75
-0
No files found.
ee/lib/ee/gitlab/ci/limit.rb
0 → 100644
View file @
599ba42d
module
EE
module
Gitlab
module
Ci
##
# Abstract base class for CI/CD Quotas
#
class
Limit
def
initialize
(
_context
,
_resource
)
end
def
enabled?
raise
NotImplementedError
end
def
exceeded?
raise
NotImplementedError
end
def
message
raise
NotImplementedError
end
end
end
end
end
ee/lib/ee/gitlab/ci/pipeline/quota/activity.rb
0 → 100644
View file @
599ba42d
module
EE
module
Gitlab
module
Ci
module
Pipeline
module
Quota
class
Activity
<
Ci
::
Limit
include
ActionView
::
Helpers
::
TextHelper
def
initialize
(
namespace
,
project
)
@namespace
=
namespace
@project
=
project
end
def
enabled?
@namespace
.
max_active_pipelines
>
0
end
def
exceeded?
return
false
unless
enabled?
excessive_pipelines_count
>
0
end
def
message
return
unless
exceeded?
'Active pipelines limit exceeded by '
\
"
#{
pluralize
(
excessive_pipelines_count
,
'pipeline'
)
}
!"
end
private
def
excessive_pipelines_count
@excessive
||=
alive_pipelines_count
-
max_active_pipelines_count
end
def
alive_pipelines_count
@project
.
pipelines
.
alive
.
count
end
def
max_active_pipelines_count
@namespace
.
max_active_pipelines
end
end
end
end
end
end
end
spec/ee/spec/lib/gitlab/ci/pipeline/quota/activity_spec.rb
0 → 100644
View file @
599ba42d
require
'spec_helper'
describe
EE
::
Gitlab
::
Ci
::
Pipeline
::
Quota
::
Activity
do
set
(
:namespace
)
{
create
(
:namespace
,
plan:
EE
::
Namespace
::
GOLD_PLAN
)
}
set
(
:project
)
{
create
(
:project
,
namespace:
namespace
)
}
let
(
:limit
)
{
described_class
.
new
(
namespace
,
project
)
}
shared_context
'pipeline activity limit exceeded'
do
before
do
create
(
:ci_pipeline
,
project:
project
,
status:
'created'
)
create
(
:ci_pipeline
,
project:
project
,
status:
'pending'
)
create
(
:ci_pipeline
,
project:
project
,
status:
'running'
)
namespace
.
plan
.
update_column
(
:active_pipelines_limit
,
1
)
end
end
shared_context
'pipeline activity limit not exceeded'
do
before
do
namespace
.
plan
.
update_column
(
:active_pipelines_limit
,
2
)
end
end
describe
'#enabled?'
do
context
'when limit is enabled in plan'
do
before
do
namespace
.
plan
.
update_column
(
:active_pipelines_limit
,
10
)
end
it
'is enabled'
do
expect
(
limit
).
to
be_enabled
end
end
context
'when limit is not enabled'
do
before
do
namespace
.
plan
.
update_column
(
:active_pipelines_limit
,
0
)
end
it
'is not enabled'
do
expect
(
limit
).
not_to
be_enabled
end
end
end
describe
'#exceeded?'
do
context
'when limit is exceeded'
do
include_context
'pipeline activity limit exceeded'
it
'is exceeded'
do
expect
(
limit
).
to
be_exceeded
end
end
context
'when limit is not exceeded'
do
include_context
'pipeline activity limit not exceeded'
it
'is not exceeded'
do
expect
(
limit
).
not_to
be_exceeded
end
end
end
describe
'#message'
do
context
'when limit is exceeded'
do
include_context
'pipeline activity limit exceeded'
it
'returns info about pipeline activity limit exceeded'
do
expect
(
limit
.
message
)
.
to
eq
"Active pipelines limit exceeded by 2 pipelines!"
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