Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Niedzielski <adamsunday@gmail.com>2017-04-03 16:17:04 +0300
committerAdam Niedzielski <adamsunday@gmail.com>2017-04-03 16:17:04 +0300
commit9543025e88d3d0fe298e95330b8d38802da50cc6 (patch)
treee96e1a10a4ba6cba5cade8cd959b3894b8e67cd8 /lib/gitlab/polling_interval.rb
parent2faf955c241ce7e99111f8fd0cae2e7ab6167e5a (diff)
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.
Diffstat (limited to 'lib/gitlab/polling_interval.rb')
-rw-r--r--lib/gitlab/polling_interval.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/gitlab/polling_interval.rb b/lib/gitlab/polling_interval.rb
new file mode 100644
index 00000000000..c44bb1cd14d
--- /dev/null
+++ b/lib/gitlab/polling_interval.rb
@@ -0,0 +1,22 @@
+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