debian-mirror-gitlab/lib/gitlab/polling_interval.rb

27 lines
678 B
Ruby
Raw Normal View History

2018-12-13 13:39:08 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
module Gitlab
class PollingInterval
2019-12-04 20:38:33 +05:30
HEADER_NAME = 'Poll-Interval'
2017-08-17 22:00:37 +05:30
def self.set_header(response, interval:)
2020-04-22 19:07:51 +05:30
response.headers[HEADER_NAME] = polling_interval_value(interval).to_s
end
def self.set_api_header(context, interval:)
context.header HEADER_NAME, polling_interval_value(interval).to_s
end
def self.polling_interval_value(interval)
return -1 unless polling_enabled?
2017-08-17 22:00:37 +05:30
2020-04-22 19:07:51 +05:30
multiplier = Gitlab::CurrentSettings.polling_interval_multiplier
(interval * multiplier).to_i
2017-08-17 22:00:37 +05:30
end
def self.polling_enabled?
2018-03-17 18:26:18 +05:30
!Gitlab::CurrentSettings.polling_interval_multiplier.zero?
2017-08-17 22:00:37 +05:30
end
end
end