blob: 0a1dff52552dc14d58e458e9414796214ea77ede (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# frozen_string_literal: true
module Gitlab
module Ci
module Pipeline
module Chain
module Limit
class RateLimit < Chain::Base
include Gitlab::Utils::StrongMemoize
RATE_LIMIT_PER_SOURCE = {
push: 10,
web: 10,
merge_request_event: 10
}.freeze
def initialize
super
limiter = ::Gitlab::ActionRateLimiter.new(action: "pipeline_creation:#{command.source}")
end
def perform!
return unless Feature.enable?(:ci_pipeline_rate_limit, pipeline.project)
return unless rate_limit_for_source
return unless throttled?
if command.save_incompleted
pipeline.drop!(:rate_limit_exceeded)
end
error('Pipeline rate limit exceeded. Please wait a minute and retry again.')
end
def break?
throttled?
end
private
def rate_limit_for_source
strong_memoize(:rate_limit_for_source) do
RATE_LIMIT_PER_SOURCE[command.source]
end
end
def throttled?
strong_memoize(:throttled) do
limiter.throttled?([pipeline.user], rate_limit_for_source)
end
end
end
end
end
end
end
end
|