Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added POLL_DELAY environment variable to UserConfiguration class #3421

Merged
merged 1 commit into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.bc_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.bc_sessions_poll_delay
active_sessions = BatchConnect::Session.all.reject { |s| s.completed? }
session_selection = active_sessions.first(max_sessions)
-%>
Expand Down
9 changes: 9 additions & 0 deletions apps/dashboard/config/configuration_singleton.rb
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,15 @@ def ood_bc_card_time
(ood_bc_card_time_int < 0) ? 0 : ood_bc_card_time_int
end

# Returns the number of milliseconds to wait between calls to the BatchConnect Sessions resource
# to update the sessions card information.
# The default and minimum value is 10s = 10_000
def bc_sessions_poll_delay
bc_poll_delay = ENV['POLL_DELAY']
bc_poll_delay_int = bc_poll_delay.nil? ? config.fetch(:sessions_poll_delay, '10000').to_i : bc_poll_delay.to_i
bc_poll_delay_int < 10_000 ? 10_000 : bc_poll_delay_int
end

def config
@config ||= read_config
end
Expand Down
27 changes: 27 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,31 @@ def no_config_env
end
end
end

test "bc_sessions_poll_delay default value" do
assert_equal(10_000, ConfigurationSingleton.new.bc_sessions_poll_delay)
end

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

test 'bc_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(99_999, ConfigurationSingleton.new.bc_sessions_poll_delay)
end
end
end

test "bc_sessions_poll_delay minimum value is 10_000" do
with_modified_env('POLL_DELAY': '100') do
assert_equal(10_000, ConfigurationSingleton.new.bc_sessions_poll_delay)
end
end
end
Loading