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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/mutx/background_jobs/workers/executor.rb', line 12
def perform(result_id)
@output = ""
Mutx::Support::Configuration.get
Mutx::Database::MongoConnector.new Mutx::Support::Configuration.db_connection_data
Mutx::Support::ChangeInspector.is_there_a_change?
result = Mutx::Results::Result.get(result_id)
result.mutx_report_file_name= "mutx_report_#{result_id}.html"
if result.is_ruby_platform?
if Mutx::Platforms::Ruby.using_bundler?
bundle_output = Mutx::Support::Console.execute "bundle install"
end
if bundle_output
result.append_output bundle_output if bundle_output.include? "Installing"
if bundle_output.include? "Could not find"
result.finish!
raise "An error ocurred installing gem while executing bundler"
else
result.append_output "All GEMS are installed and running!\n"
result.append_output "=========================\n"
result.append_output "EXECUTION OUTPUT:\n"
result.append_output "=========================\n"
end
end
end
Dir.mkdir "#{Dir.pwd}/mutx/temp" unless Dir.exist? "#{Dir.pwd}/mutx/temp"
cucumber_report_command = result.is_cucumber? ? "-f pretty -f html -o mutx/temp/#{result.mutx_report_file_name}" : ""
result.mutx_command= "#{Mutx::Support::Configuration.headless?} #{result.command} #{cucumber_report_command} #{result.custom_params_values} _id=#{result.id} "
Mutx::Support::Log.debug "[result:#{result.id}] Creating process" if Mutx::Support::Log
result.running!
Mutx::Support::Log.debug "[result:#{result.id}] setted as running" if Mutx::Support::Log
@output = ""
@count = 0
if Mutx::Support::Configuration.use_git?
Mutx::Support::Git.pull unless Mutx::Support::Git.up_to_date?
end
IO.popen("#{result.mutx_command}") do |data|
result.pid ="#{`ps -fea | grep #{Process.pid} | grep -v grep | awk '$2!=#{Process.pid} && $8!~/awk/ && $3==#{Process.pid}{print $2}'`}"
result.save!
while line = data.gets
@count += 1
@output += line
if @count == 30
result.append_output @output
@output = ""
@count = 0
end
if result.seconds_without_changes > Mutx::Support::Configuration.execution_time_to_live
result.finished_by_timeout! and break
end
end
result.append_output @output unless @output.empty?
result.append_output "=========================\n"
end
result.ensure_finished!
Mutx::Support::Log.debug "[result:#{result.id}]| command => #{result.mutx_command} | result as => #{result.status}" if Mutx::Support::Log
end
|