Class: ScoutAgent::Assignment::UploadLog
- Inherits:
-
ScoutAgent::Assignment
- Object
- ScoutAgent::Assignment
- ScoutAgent::Assignment::UploadLog
- Defined in:
- lib/scout_agent/assignment/upload_log.rb
Instance Attribute Summary
Attributes inherited from ScoutAgent::Assignment
#group, #other_args, #switches, #user
Instance Method Summary collapse
Methods inherited from ScoutAgent::Assignment
#initialize, #prepare_and_execute
Methods included from Tracked
#clear_status, #force_status_database_reload, #status, #status_database, #status_log
Constructor Details
This class inherits a constructor from ScoutAgent::Assignment
Instance Method Details
#execute ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/scout_agent/assignment/upload_log.rb', line 10 def execute file_name = "#{ScoutAgent.agent_name}.log" if date = Array(other_args).shift file_name += ".#{date.delete('^0-9')}" end log_file = Plan.log_dir + file_name unless log_file.exist? abort_with_not_found(file_name) end puts "Preparing file for the server. This may take a moment..." begin upload_file = Tempfile.new("#{file_name}.gz") gzipped = Zlib::GzipWriter.new(upload_file) log_file.each_line do |line| gzipped << line end gzipped.close upload_file.open # reopen what Zlib closed rescue Exception => error # Zlib or IOError abort_with_preparation_error(error) end puts "Done." puts "Sending file to the server. This may take a moment..." server = Server.new if server.post_log(upload_file) puts "Log '#{file_name}' received. Thanks." else abort_with_server_error end end |