3782: load only 1 MB of job logs
authorTim Pierce <twp@curoverse.com>
Tue, 23 Sep 2014 20:39:03 +0000 (16:39 -0400)
committerTim Pierce <twp@curoverse.com>
Tue, 23 Sep 2014 21:30:07 +0000 (17:30 -0400)
apps/workbench/app/controllers/collections_controller.rb

index f87579e3b2570fc48a610ea7c61ae7d3fa5d7fa7..aee3d2a3301d3a21c326a2c2a5b9f39c524fc2f0 100644 (file)
@@ -297,11 +297,17 @@ class CollectionsController < ApplicationController
       env['ARVADOS_API_TOKEN'] = @opts[:arvados_api_token]
       env['ARVADOS_API_HOST_INSECURE'] = "true" if Rails.configuration.arvados_insecure_https
 
+      maxbytes = @opts[:maxbytes] || 1000000
+      bytesleft = maxbytes
       IO.popen([env, 'arv-get', "#{@opts[:uuid]}/#{@opts[:file]}"],
                'rb') do |io|
-        while buf = io.read(2**16)
+        while bytesleft > 0 && buf = io.read(bytesleft)
+          bytesleft = bytesleft - buf.length
           yield buf
         end
+        if bytesleft == 0 then
+          yield "Log truncated (exceeded #{maxbytes} bytes). To retrieve the full log: arv-get #{@opts[:uuid]}/#{@opts[:file]}"
+        end
       end
       Rails.logger.warn("#{@opts[:uuid]}/#{@opts[:file]}: #{$?}") if $? != 0
     end