Skip to content

Commit

Permalink
Added POLL_DELAY environment variable to Configuration class
Browse files Browse the repository at this point in the history
  • Loading branch information
abujeda committed Mar 14, 2024
1 parent 8a7bf69 commit 3107f1f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ locals: {
%>
</div>
<div class="col-md-9">
<div id="batch_connect_sessions" class="batch-connect sessions" data-toggle="poll" data-url="<%= batch_connect_sessions_path(format: :js) %>" data-delay="<%= ENV["POLL_DELAY"] || 10000 %>">
<div id="batch_connect_sessions" class="batch-connect sessions" data-toggle="poll" data-url="<%= batch_connect_sessions_path(format: :js) %>" data-delay="<%= Configuration.sessions_poll_delay %>">
<% if @sessions.empty? %>
<div class="ood-appkit markdown">
<p><%= t('dashboard.batch_connect_no_sessions') %></p>
Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/app/views/widgets/_sessions.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%-
max_sessions = 3
poll_delay = ENV["POLL_DELAY"] || 10000
poll_delay = Configuration.sessions_poll_delay
active_sessions = BatchConnect::Session.all.reject { |s| s.completed? }
session_selection = active_sessions.first(max_sessions)
-%>
Expand Down
5 changes: 5 additions & 0 deletions apps/dashboard/config/configuration_singleton.rb
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,11 @@ def ood_bc_card_time
(ood_bc_card_time_int < 0) ? 0 : ood_bc_card_time_int
end

def sessions_poll_delay
poll_delay = ENV['POLL_DELAY']
poll_delay.nil? ? config.fetch(:sessions_poll_delay, '10000') : poll_delay.to_s
end

def config
@config ||= read_config
end
Expand Down
21 changes: 21 additions & 0 deletions apps/dashboard/test/config/configuration_singleton_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -496,4 +496,25 @@ def no_config_env
end
end
end

test "sessions_poll_delay default value" do
assert_equal('10000', ConfigurationSingleton.new.sessions_poll_delay)
end

test "sessions_poll_delay reads value from environment" do
with_modified_env('POLL_DELAY': '20000') do
assert_equal('20000', ConfigurationSingleton.new.sessions_poll_delay)
end
end

test 'sessions_poll_delay reads from config' do
Dir.mktmpdir do |dir|
with_modified_env({ OOD_CONFIG_D_DIRECTORY: dir.to_s }) do
sessions_config = { 'sessions_poll_delay' => '99999' }
File.open("#{dir}/sessions_config.yml", 'w+') { |f| f.write(sessions_config.to_yaml) }

assert_equal('99999', ConfigurationSingleton.new.sessions_poll_delay)
end
end
end
end

0 comments on commit 3107f1f

Please sign in to comment.