lib/mutx/tasks/task.rb in mutx-0.1.15 vs lib/mutx/tasks/task.rb in mutx-0.1.16

- old
+ new

@@ -15,11 +15,10 @@ :name, :branch, :type, :platform, :framework, - :status, :command, :custom_params, :information, :cucumber, :max_execs, @@ -46,11 +45,10 @@ @name = task_data["name"] @branch = task_data["branch"] @type = task_data["type"] || "task" @platform = task_data["platform"] || "command line" @framework = task_data["framework"] - @status = task_data["status"] @command = task_data["command"] @custom_params = task_data["custom_params"] || [] @information = task_data["information"] @running_execs = [] @cucumber = task_data["cucumber"] @@ -73,11 +71,12 @@ def api_response response = task_data_structure response["results"]={ "size" => number_of_results, - "ids" => all_results_ids + "ids" => all_results_ids, + "status" => status } response end def self.get task_id @@ -101,11 +100,10 @@ "type" => data["type"], "platform" => data["platform"], "information" => data["information"], "cucumber" => data["cucumber"], "branch" => Mutx::Support::Git.actual_branch, - "status" => "READY", "max_execs" => data["max_execs"], "custom_params" => data["custom_params"], "cronneable" => data["cronneable"], "cron_time" => data["cron_time"], "mail" => data["mail"], @@ -127,23 +125,19 @@ end end def self.validate(data) - # cucumber value must be boolean errors = [] if data["action"] == "edit" errors << self.validate_name_with_id(data["name"],data["_id"]) else errors << self.validate_name(data["name"]) end - errors << self.validate_max_execs(data["max_execs"]) - errors << self.validate_type(data["type"]) - errors << self.validate_risk_command(data["command"]) errors.compact end def self.validate_and_update(data) @@ -209,11 +203,10 @@ { "_id" => id, "name" => name, "branch" => branch, "type" => type, - "status" => status, "command" => command, "custom_params" => custom_params, "information" => information, "running_execs" => running_execs, "max_execs" => max_execs, @@ -240,32 +233,10 @@ def test? self.type == "test" end - def is_ready? - status == "READY" - end - - def is_running? - status == "RUNNING" - end - - def set_ready! - if Mutx::Tasks.number_of_running_executions_for_task(@name).zero? - @status = "READY" - Mutx::Support::Log.debug "[#{@id}:#{@name}] Marked as ready" if Mutx::Support::Log - self.save! - end - end - - def set_running! - @status= "RUNNING" - Mutx::Support::Log.debug "[#{@id}:#{@name}] Marked as running" if Mutx::Support::Log - self.save! - end - def push_exec result_id @running_execs << result_id self.save! end @@ -276,10 +247,14 @@ def number_of_results all_results.size end + def number_of_running_results + all_results.select{|res| res["status"] == "RUNNING"}.size + end + def all_results_ids all_results.inject([]){|res, result| res << result["_id"]} end def all_results @@ -288,21 +263,24 @@ def has_results? number_of_results > 0 end + def status + if number_of_running_results > 0 + "RUNNING" + else + "IDLE" + end + end + def save! if Mutx::Database::MongoConnector.task_data_for(id) Mutx::Database::MongoConnector.update_task(task_data_structure) else Mutx::Database::MongoConnector.insert_task(task_data_structure) end Mutx::Support::Log.debug "[#{@id}:#{@name}] Task saved" if Mutx::Support::Log - end - - # If test tasks ir running - def check_last_result! - raise "NO SE PUEDE USAR MAS ESTO, AHORA HAY QUE CHEQUEAR POR SEPARADO" end end end \ No newline at end of file