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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
# File 'lib/mutx/background_jobs/workers/executor.rb', line 15
def perform(result_id)
@output = ""
Mutx::Support::Configuration.get
Mutx::Database::MongoConnector.new Mutx::Support::Configuration.db_connection_data
result = Mutx::Results::Result.get(result_id)
puts "[#{result.id}] Execution created"
task = Mutx::Tasks::Task.get(result.task_id)
result.mutx_report_file_name= "mutx_report_#{result_id}.html"
Mutx::Support::Bundle.new.bundle_update(result) if Mutx::Support::ChangeInspector.is_there_a_change?
Dir.mkdir "#{Dir.pwd}/mutx/temp" unless Dir.exist? "#{Dir.pwd}/mutx/temp"
efective_command = []
efective_command << Mutx::Support::Configuration.headless? if result.gui_task?
efective_command << result.command
efective_command << "-f pretty -f html -o mutx/temp/#{result.mutx_report_file_name}" if result.is_cucumber?
efective_command << result.custom_params_values
efective_command << "_id=#{result.id}"
puts "[#{result.id}] Command: #{efective_command.join(" ")}"
result.mutx_command = efective_command.join(" ")
attach_folder = "#{Dir.pwd}/mutx/out/#{result.id}/attachment"
result.running!
puts "[#{result.id}] setted as running"
if !Mutx::Support::Configuration.proxys.empty?
Mutx::Support::Configuration.proxys.detect{|proxy| Mutx::Support::Console.execute proxy}
end
Mutx::Support::TimeHelper.start
begin
PTY.spawn( "#{result.mutx_command}" ) do |stdout, stdin, pid|
begin
stdout.each { |line|
@output = line
@output.slice! "fatal: Not a git repository (or any of the parent directories): .git"
result.append_output! @output.gsub(/(\[\d{1,2}\m)/, "")
if result.time_to_live_reached?
result.finished_by_timeout! and break
end
}
Process.wait pid
result.append_output! @output unless @output.empty?
rescue Errno::EIO
end
end
rescue PTY::ChildExited => e
puts "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
puts "The child process exited!, #{e.message}"
puts "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
rescue Errno::ENOENT => e
cmd = result.mutx_command.match(/(\D*)\_/)[0].delete"_"
exception_message = "EXCEPTION: #{e.message} for the command requested for you: #{cmd.upcase}"
puts "[#{result.id}] exception_message: #{exception_message}"
@output = exception_message
result.append_output! @output unless @output.empty?
end
puts "[#{result.id}] Status before ensure finish => #{result.status}"
result.ensure_finished!
result.eval_regex!
puts "[#{result.id}] ensure finished"
puts result.summary
task = Mutx::Database::MongoConnector.task_data_for result.task[:id]
subject = if ((task[:subject].empty?) || (task[:subject].nil?))
result.console_output.match(/\SUBJECT(.*)/)[1] if result.console_output.include? "SUBJECT" || task[:name]
else
task[:subject]
end
email = task[:mail]
type = task[:type]
name = task[:name]
id = task[:_id]
cucumber = task[:cucumber]
notify_on = task[:notify_on]
result.eval_regex!
if ( (task["notifications"].eql? "on") && (!task["stop_bots"].eql? "on") && (!task["stop_bots"].eql? "off") && (!result.regex.empty?) && (result.console_output.to_s.include? "#{result.regex.to_s}") )
Mutx::Database::MongoConnector.mark_notified (result_id)
Mutx::Workers::EmailSender.perform_async(result_id, subject, email, name, id, type, cucumber, notify_on, attach_folder) if ((task[:notifications].eql? "on") && (!email.empty?))
elsif ( (task["notifications"].eql? "on") && (!task["stop_bots"].eql? "on") && (!task["stop_bots"].eql? "off") && (result.regex.empty?) )
Mutx::Database::MongoConnector.mark_notified (result_id)
Mutx::Workers::EmailSender.perform_async(result_id, subject, email, name, id, type, cucumber, notify_on, attach_folder) if ((task[:notifications].eql? "on") && (!email.empty?))
elsif ( (task["notifications"].eql? "on") && (task["stop_bots"].eql? "on") && (!result.regex.empty?) && (result.console_output.to_s.include? "#{result.regex.to_s}") )
Mutx::Database::MongoConnector.mark_notified (result_id)
Mutx::Workers::EmailSender.perform_async(result_id, subject, email, name, id, type, cucumber, notify_on, attach_folder) if ((task[:notifications].eql? "on") && (!email.empty?))
Mutx::Database::MongoConnector.update_stop_bots_off (id)
Mutx::Support::MailSender.new.sender(nil, "#{name} Comenzo a notificar, se le informara cuando vuelva a la normalidad", "#{email}", name, nil, nil, nil, nil, nil)
elsif ( (task["notifications"].eql? "on") && (task["stop_bots"].eql? "off") && (!result.regex.empty?) && (!result.console_output.to_s.include? "#{result.regex.to_s}") )
Mutx::Database::MongoConnector.update_stop_bots_on (id)
Mutx::Support::MailSender.new.sender(nil, "#{name} Volvio a funcionar con normalidad", "#{email}", name, nil, nil, nil, nil, nil)
elsif ( (task["notifications"].eql? "on") && (!result.regex.empty?) && (!result.console_output.to_s.include? "#{result.regex.to_s}") )
puts "****Result not to being notified, because regex #{result.regex.to_s} not included on output****"
end
puts "[result:#{result.id}]| command => #{result.mutx_command} | result as => #{result.status}"
Mutx::Database::MongoConnector.force_close
end
|