Advertisement
andrey_zavyalov

Untitled

Mar 13th, 2024
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. module Reports
  2. class Common
  3. def input_hash
  4. input_data
  5. end
  6.  
  7. def input_json
  8. input_data.to_json
  9. end
  10.  
  11. def output_data
  12. return @output_data if @output_data
  13.  
  14. tmp_file = Tempfile.new
  15. File.write(tmp_file.path, input_data.to_json)
  16.  
  17. measure = MeasureMemoryUsageTimeSpeed.run_and_measure do
  18. Open3.capture3(command(tmp_file))
  19. end
  20. # TODO: store these data
  21. # measure[:time_spent_seconds]
  22. # measure[:memory_usage_kb]
  23.  
  24. command_out, command_error, command_status = measure[:block_result]
  25. command_result = { command_out: command_out,
  26. command_error: command_error,
  27. command_status: command_status.to_i }
  28.  
  29. raise(StandardError, "command '#{python_script_name}' has non-zero result") unless command_status.to_i.zero?
  30.  
  31. @output_data = JSON.parse(command_out, { allow_nan: true })
  32. rescue StandardError => e
  33. puts command_result
  34. ::CbsPlatform::ErrorReporter.error(
  35. e,
  36. "Can't generate #{report_type} report data (report ID = #{report_id}, command_result=#{command_result})"
  37. )
  38.  
  39. nil
  40. command_result
  41. ensure
  42. tmp_file&.close
  43. tmp_file&.unlink
  44. end
  45. end
  46. end
  47.  
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement