gitlab-org--gitlab-foss/lib/gitlab/polling_interval.rb
Adam Niedzielski 9543025e88 Introduce "polling_interval_multiplier" as application setting
Implement module for setting "Poll-Interval" response header.
Return 429 in ETag caching middleware when polling is disabled.
2017-04-03 15:17:04 +02:00

22 lines
523 B
Ruby

module Gitlab
class PollingInterval
include Gitlab::CurrentSettings
HEADER_NAME = 'Poll-Interval'.freeze
def self.set_header(response, interval:)
if polling_enabled?
multiplier = current_application_settings.polling_interval_multiplier
value = (interval * multiplier).to_i
else
value = -1
end
response.headers[HEADER_NAME] = value
end
def self.polling_enabled?
!current_application_settings.polling_interval_multiplier.zero?
end
end
end