From aa7ec423d92b977320cc5708bd9556021d50d77a Mon Sep 17 00:00:00 2001 From: radhika Date: Tue, 20 May 2014 16:21:15 -0400 Subject: [PATCH] 2756: write log info from redis into log table. this will help us read this log info via the event log websockets. --- services/api/script/crunch-dispatch.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/services/api/script/crunch-dispatch.rb b/services/api/script/crunch-dispatch.rb index 43a527afac..5cf7cac7e2 100755 --- a/services/api/script/crunch-dispatch.rb +++ b/services/api/script/crunch-dispatch.rb @@ -29,6 +29,10 @@ require 'open3' $redis ||= Redis.new LOG_BUFFER_SIZE = 2**20 +$tmp_log_buffer = '' +$previous_tmp_log_at = Time.now +TMP_LOG_BUFFER_SIZE = 4096 + class Dispatcher include ApplicationHelper @@ -259,6 +263,13 @@ class Dispatcher .getrange(job_uuid, (LOG_BUFFER_SIZE >> 1), -1) .sub(/^.*?\n/, '')) end + + if (TMP_LOG_BUFFER_SIZE < $tmp_log_buffer.size) || ($previous_tmp_log_at+1 < Time.now) + $tmp_log_buffer += (pub_msg + "\n") + write_log job_uuid + else + $tmp_log_buffer += (pub_msg + "\n") + end end end end @@ -306,6 +317,8 @@ class Dispatcher # Ensure every last drop of stdout and stderr is consumed read_pipes + write_log job_done.uuid # write any remaining logs + if j_done[:stderr_buf] and j_done[:stderr_buf] != '' $stderr.puts j_done[:stderr_buf] + "\n" end @@ -400,6 +413,19 @@ class Dispatcher true end end + + # send message to log table. we want these records to be transient + def write_log job_uuid + if $tmp_log_buffer == '' + return + end + log = Log.new(object_uuid: job_uuid, + event_type:'transient-log-entry', + summary: $tmp_log_buffer) + log.save! + $tmp_log_buffer = '' + $previous_tmp_log_at = Time.now + end end # This is how crunch-job child procs know where the "refresh" trigger file is -- 2.30.2