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

27 lines
676 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?
2020-10-24 23:57:45 +05:30
Gitlab::CurrentSettings.polling_interval_multiplier != 0
2017-08-17 22:00:37 +05:30
end
end
end