lib/mutx/API/execution.rb in mutx-0.1.69 vs lib/mutx/API/execution.rb in mutx-0.2.0
- old
+ new
@@ -23,13 +23,12 @@
error = false
running_started = []
running_started = Mutx::Database::MongoConnector.running_for_task task_name
- is_there_task = Mutx::Tasks.is_there_task_with? task_name, type
- if ((is_there_task) && (running_started.empty?))
+ if Mutx::Tasks.is_there_task_with? task_name, type
Mutx::Support::Log.debug "Starting working with task #{task_name}" if Mutx::Support::Log
task = Mutx::Tasks::Task.get_task_with(task_name)
task_id = task.id
@@ -49,14 +48,12 @@
"started_message" => "#{task.type.capitalize} #{task.name} started"
}
execution_id = Mutx::Execution.run!(execution_request_data)
- task.push_exec execution_id
+ task.push_exec! execution_id
- task.save!
-
Mutx::Support::Log.debug "Task #{task_name} setted as running" if Mutx::Support::Log
started = true
message = "#{task.type.capitalize} #{task.name} started"
status = 200
@@ -99,49 +96,16 @@
#
# Kill associated process to the running execution
# Sets as finished the result and associated task as READY
#
def self.reset(result_id)
-
- Mutx::Support::Log.debug "Reset execution request for #{result_id}"
-
result = Mutx::Results::Result.get(result_id)
-
- task = Mutx::Tasks::Task.get(result.task_id)
- # if is the owner
- if result.process_running? or !result.finished? or !result.stopped?
- begin
- if result.pid
- killed = true
- Mutx::Support::Processes.kill_p(result.pid)
- Mutx::Support::Log.debug "Execution (id=#{result.id}) killed: #{killed}"
- end
- rescue => e
- Mutx::Support::Log.error "#{e}#{e.backtrace}"
- end
-
- begin
- Mutx::Support::FilesCleanner.delete_report_which_has(result.id)
- Mutx::Support::Log.debug "Execution files(id=#{result.id}) cleanned"
- cleanned = true
- rescue
- end
-
- result.save_report
- result.reset!("forced");
- Mutx::Support::Log.debug "Execution stopped!"
- result.show_as = "pending"
- result.save!
-
- if killed
- message = "Execution: Stopped (forced) "
- message += " Files: Cleanned" if cleanned
- else
- message = "Could not stop execution. Process killing: #{killed}. Files cleanned: #{cleanned}"
-
- end
-
- end
+
+ message = if result.reset!
+ "[#{result.id}] Execution stopped"
+ else
+ "[#{result.id}] Could not stop execution"
+ end
{"message" => message}
end
end
end
\ No newline at end of file