From 730eb182b2160040a902feb09276b75a3f9c137c Mon Sep 17 00:00:00 2001 From: Tom Clegg Date: Tue, 30 Aug 2016 16:30:17 -0400 Subject: [PATCH] 9799: Fix up live_log_lines so it works for all work units. --- .../workbench/app/models/container_work_unit.rb | 7 ------- apps/workbench/app/models/job.rb | 3 +-- apps/workbench/app/models/proxy_work_unit.rb | 9 +++++++++ .../test/integration/websockets_test.rb | 17 +++++++---------- 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/apps/workbench/app/models/container_work_unit.rb b/apps/workbench/app/models/container_work_unit.rb index 42a4f4bd5b..c8af093e8f 100644 --- a/apps/workbench/app/models/container_work_unit.rb +++ b/apps/workbench/app/models/container_work_unit.rb @@ -134,13 +134,6 @@ class ContainerWorkUnit < ProxyWorkUnit [get_combined(:uuid), get(:uuid)].uniq end - def live_log_lines(limit=2000) - event_types = ["stdout", "stderr", "arv-mount", "crunch-run"] - log_lines = Log.where(event_type: event_types, object_uuid: log_object_uuids).order("id DESC").limit(limit) - log_lines.results.reverse. - flat_map { |log| log.properties[:text].split("\n") rescue [] } - end - def render_log collection = Collection.find(log_collection) rescue nil if collection diff --git a/apps/workbench/app/models/job.rb b/apps/workbench/app/models/job.rb index 73f1f63be4..bf202c4eaa 100644 --- a/apps/workbench/app/models/job.rb +++ b/apps/workbench/app/models/job.rb @@ -43,8 +43,7 @@ class Job < ArvadosBase end def stderr_log_query(limit=nil) - query = Log.where(event_type: "stderr", object_uuid: self.uuid) - .order("id DESC") + query = Log.where(object_uuid: self.uuid).order("created_at DESC") query = query.limit(limit) if limit query end diff --git a/apps/workbench/app/models/proxy_work_unit.rb b/apps/workbench/app/models/proxy_work_unit.rb index feab5d8eb4..11ec0ee196 100644 --- a/apps/workbench/app/models/proxy_work_unit.rb +++ b/apps/workbench/app/models/proxy_work_unit.rb @@ -332,6 +332,15 @@ class ProxyWorkUnit < WorkUnit [uuid] end + def live_log_lines(limit) + Log.where(object_uuid: log_object_uuids). + order("created_at DESC"). + limit(limit). + select { |log| log.properties[:text].is_a? String }. + reverse. + flat_map { |log| log.properties[:text].split("\n") } + end + protected def get key, obj=@proxied diff --git a/apps/workbench/test/integration/websockets_test.rb b/apps/workbench/test/integration/websockets_test.rb index 3cfd792e8d..54712d396a 100644 --- a/apps/workbench/test/integration/websockets_test.rb +++ b/apps/workbench/test/integration/websockets_test.rb @@ -201,7 +201,6 @@ class WebsocketTest < ActionDispatch::IntegrationTest test "test running job with just a few previous log records" do job = api_fixture("jobs")['running'] - visit page_with_token("active", "/jobs/#{job['uuid']}") # Create just one old log record dispatch_log(owner_uuid: job['owner_uuid'], @@ -209,7 +208,7 @@ class WebsocketTest < ActionDispatch::IntegrationTest event_type: "stderr", properties: {"text" => "Historic log message"}) - click_link("Log") + visit page_with_token("active", "/jobs/#{job['uuid']}\#Log") # Expect "all" historic log records because we have less than # default Rails.configuration.running_job_log_records_to_fetch count @@ -224,25 +223,23 @@ class WebsocketTest < ActionDispatch::IntegrationTest end test "test running job with too many previous log records" do - Rails.configuration.running_job_log_records_to_fetch = 5 - + max = 5 + Rails.configuration.running_job_log_records_to_fetch = max job = api_fixture("jobs")['running'] - visit page_with_token("active", "/jobs/#{job['uuid']}") - # Create Rails.configuration.running_job_log_records_to_fetch + 1 log records - (0..Rails.configuration.running_job_log_records_to_fetch).each do |count| + # Create max+1 log records + (0..max).each do |count| dispatch_log(owner_uuid: job['owner_uuid'], object_uuid: job['uuid'], event_type: "stderr", properties: {"text" => "Old log message #{count}"}) end - # Go to log tab, which results in subscribing to websockets - click_link("Log") + visit page_with_token("active", "/jobs/#{job['uuid']}\#Log") # Expect all but the first historic log records, # because that was one too many than fetch count. - (1..Rails.configuration.running_job_log_records_to_fetch).each do |count| + (1..max).each do |count| assert_text "Old log message #{count}" end assert_no_text 'Old log message 0' -- 2.30.2