2018-10-22 03:00:50 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-03 09:17:04 -04:00
|
|
|
module Gitlab
|
|
|
|
class PollingInterval
|
2019-08-31 15:25:25 -04:00
|
|
|
HEADER_NAME = 'Poll-Interval'
|
2017-04-03 09:17:04 -04:00
|
|
|
|
|
|
|
def self.set_header(response, interval:)
|
2020-03-20 14:09:31 -04:00
|
|
|
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-04-03 09:17:04 -04:00
|
|
|
|
2020-03-20 14:09:31 -04:00
|
|
|
multiplier = Gitlab::CurrentSettings.polling_interval_multiplier
|
|
|
|
(interval * multiplier).to_i
|
2017-04-03 09:17:04 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.polling_enabled?
|
2020-08-05 11:09:59 -04:00
|
|
|
Gitlab::CurrentSettings.polling_interval_multiplier != 0
|
2017-04-03 09:17:04 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|