Class: Mutx::Tasks::Task
- Inherits:
-
Object
- Object
- Mutx::Tasks::Task
- Defined in:
- lib/mutx/tasks/task.rb
Constant Summary collapse
- REGEX_VALID_VALUES =
["failed","passed","none"]
- NOTIFY_VALID_VALUES =
["any","passed","failed"]
Instance Attribute Summary collapse
-
#application ⇒ Object
Task means what a user can Run.
-
#blocked ⇒ Object
Task means what a user can Run.
-
#blocked_stop ⇒ Object
Task means what a user can Run.
-
#branch ⇒ Object
Task means what a user can Run.
-
#command ⇒ Object
Task means what a user can Run.
-
#cron_time ⇒ Object
Task means what a user can Run.
-
#cronneable ⇒ Object
Task means what a user can Run.
-
#cucumber ⇒ Object
Task means what a user can Run.
-
#custom_params ⇒ Object
Task means what a user can Run.
-
#fr ⇒ Object
Task means what a user can Run.
-
#framework ⇒ Object
Task means what a user can Run.
-
#id ⇒ Object
Task means what a user can Run.
-
#information ⇒ Object
Task means what a user can Run.
-
#last_exec_time ⇒ Object
Task means what a user can Run.
-
#mail ⇒ Object
Task means what a user can Run.
-
#max_execs ⇒ Object
Task means what a user can Run.
-
#mo ⇒ Object
Task means what a user can Run.
-
#name ⇒ Object
Task means what a user can Run.
-
#notifications ⇒ Object
Task means what a user can Run.
-
#notify_on ⇒ Object
Task means what a user can Run.
-
#platform ⇒ Object
Task means what a user can Run.
-
#regex ⇒ Object
Task means what a user can Run.
-
#running_execs ⇒ Object
Task means what a user can Run.
-
#sa ⇒ Object
Task means what a user can Run.
-
#start_time ⇒ Object
Task means what a user can Run.
-
#stop_bots ⇒ Object
Task means what a user can Run.
-
#stop_time ⇒ Object
Task means what a user can Run.
-
#su ⇒ Object
Task means what a user can Run.
-
#subject ⇒ Object
Task means what a user can Run.
-
#th ⇒ Object
Task means what a user can Run.
-
#tu ⇒ Object
Task means what a user can Run.
-
#type ⇒ Object
Task means what a user can Run.
-
#value_for_regex ⇒ Object
Task means what a user can Run.
-
#we ⇒ Object
Task means what a user can Run.
Class Method Summary collapse
- .delete_this(data) ⇒ Object
- .get(task_id) ⇒ Object
- .get_task_with(name) ⇒ Object
- .new_task(data) ⇒ Object
- .valid_types ⇒ Object
- .validate(data) ⇒ Object
- .validate_and_create(data) ⇒ Object
- .validate_and_update(data) ⇒ Object
-
.validate_max_execs(max_execs) ⇒ Object
max_execs could not be greater than global max exec.
-
.validate_name(name) ⇒ Object
task name must be unique.
- .validate_name_with_id(name, id) ⇒ Object
- .validate_notifications(notify_on = nil, notifications = nil, recipients = nil) ⇒ Object
-
.validate_risk_command(command) ⇒ Object
command must be evaluated for risks.
-
.validate_type(type) ⇒ Object
type could be only task or test.
- .validate_value_for_regex(value_for_regex = nil, regex = nil, cucumber = nil) ⇒ Object
Instance Method Summary collapse
- #all_results ⇒ Object
- #all_results_ids ⇒ Object
- #api_response ⇒ Object
- #delete_exec(result_id) ⇒ Object
- #has_custom_params? ⇒ Boolean
- #has_info? ⇒ Boolean
- #has_results? ⇒ Boolean
-
#initialize(task_data = nil) ⇒ Task
constructor
First, try to get task info from mongo.
- #number_of_results ⇒ Object
- #number_of_running_results ⇒ Object
- #push_exec(result_id) ⇒ Object
- #save! ⇒ Object
- #status ⇒ Object
- #task_data_for(task_name) ⇒ Object
-
#task_data_structure ⇒ Hash
Returns the structure of a task data.
- #test? ⇒ Boolean
Constructor Details
#initialize(task_data = nil) ⇒ Task
First, try to get task info from mongo. If it does not exist creates a new one with default values
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 |
# File 'lib/mutx/tasks/task.rb', line 58 def initialize task_data = nil Mutx::Support::Log.debug "[#{task_data["_id"]}:#{task_data["name"]}] Creating task object " if Mutx::Support::Log if task_data.is_a? Hash @id = task_data["_id"] @name = task_data["name"] @branch = task_data["branch"] @type = task_data["type"] || "task" @platform = task_data["platform"] || "command line" @framework = task_data["framework"] @command = task_data["command"] @custom_params = task_data["custom_params"] || [] @information = task_data["information"] @running_execs = [] @cucumber = task_data["cucumber"] @cucumber_report = task_data["cucumber_report"] @max_execs = task_data["max_execs"] || Mutx::Support::Configuration.maximum_execs_per_task @cronneable = task_data["cronneable"] @cron_time = task_data["cron_time"] @mail = task_data["mail"] @subject = task_data["subject"] || "" @notifications = task_data["notifications"] @blocked = task_data["blocked"] @blocked_stop = task_data["blocked_stop"] @last_exec_time = task_data["last_exec_time"] @application = task_data["application"] || "command line" @regex = task_data["regex"] @value_for_regex = task_data["value_for_regex"] @mo = task_data["mo"] @tu = task_data["tu"] @we = task_data["we"] @th = task_data["th"] @fr = task_data["fr"] @sa = task_data["sa"] @su = task_data["su"] @start_time = task_data["start_time"] @stop_time = task_data["stop_time"] @notify_on = task_data["notify_on"] || "any" @stop_bots = task_data["stop_bots"] else Mutx::Support::Log.error "Creting task object. Argument is not a hash" if Mutx::Support::Log raise "Task data not defined correctly. Expecting info about task" end save! end |
Instance Attribute Details
#application ⇒ Object
Task means what a user can Run. It coul be a test or a tests suites according to the test organization and the used framework There are two types of task: A task properly said and a test. A platform can be specified. It could be one of following:
"bash" => Aimed to run bash commands
"ruby" => When you want to run ruby code
"java" => Well, if you wanto to do it, poor you :P
14 15 16 |
# File 'lib/mutx/tasks/task.rb', line 14 def application @application end |
#blocked ⇒ Object
Task means what a user can Run. It coul be a test or a tests suites according to the test organization and the used framework There are two types of task: A task properly said and a test. A platform can be specified. It could be one of following:
"bash" => Aimed to run bash commands
"ruby" => When you want to run ruby code
"java" => Well, if you wanto to do it, poor you :P
14 15 16 |
# File 'lib/mutx/tasks/task.rb', line 14 def blocked @blocked end |
#blocked_stop ⇒ Object
Task means what a user can Run. It coul be a test or a tests suites according to the test organization and the used framework There are two types of task: A task properly said and a test. A platform can be specified. It could be one of following:
"bash" => Aimed to run bash commands
"ruby" => When you want to run ruby code
"java" => Well, if you wanto to do it, poor you :P
14 15 16 |
# File 'lib/mutx/tasks/task.rb', line 14 def blocked_stop @blocked_stop end |
#branch ⇒ Object
Task means what a user can Run. It coul be a test or a tests suites according to the test organization and the used framework There are two types of task: A task properly said and a test. A platform can be specified. It could be one of following:
"bash" => Aimed to run bash commands
"ruby" => When you want to run ruby code
"java" => Well, if you wanto to do it, poor you :P
14 15 16 |
# File 'lib/mutx/tasks/task.rb', line 14 def branch @branch end |
#command ⇒ Object
Task means what a user can Run. It coul be a test or a tests suites according to the test organization and the used framework There are two types of task: A task properly said and a test. A platform can be specified. It could be one of following:
"bash" => Aimed to run bash commands
"ruby" => When you want to run ruby code
"java" => Well, if you wanto to do it, poor you :P
14 15 16 |
# File 'lib/mutx/tasks/task.rb', line 14 def command @command end |
#cron_time ⇒ Object
Task means what a user can Run. It coul be a test or a tests suites according to the test organization and the used framework There are two types of task: A task properly said and a test. A platform can be specified. It could be one of following:
"bash" => Aimed to run bash commands
"ruby" => When you want to run ruby code
"java" => Well, if you wanto to do it, poor you :P
14 15 16 |
# File 'lib/mutx/tasks/task.rb', line 14 def cron_time @cron_time end |
#cronneable ⇒ Object
Task means what a user can Run. It coul be a test or a tests suites according to the test organization and the used framework There are two types of task: A task properly said and a test. A platform can be specified. It could be one of following:
"bash" => Aimed to run bash commands
"ruby" => When you want to run ruby code
"java" => Well, if you wanto to do it, poor you :P
14 15 16 |
# File 'lib/mutx/tasks/task.rb', line 14 def cronneable @cronneable end |
#cucumber ⇒ Object
Task means what a user can Run. It coul be a test or a tests suites according to the test organization and the used framework There are two types of task: A task properly said and a test. A platform can be specified. It could be one of following:
"bash" => Aimed to run bash commands
"ruby" => When you want to run ruby code
"java" => Well, if you wanto to do it, poor you :P
14 15 16 |
# File 'lib/mutx/tasks/task.rb', line 14 def cucumber @cucumber end |
#custom_params ⇒ Object
Task means what a user can Run. It coul be a test or a tests suites according to the test organization and the used framework There are two types of task: A task properly said and a test. A platform can be specified. It could be one of following:
"bash" => Aimed to run bash commands
"ruby" => When you want to run ruby code
"java" => Well, if you wanto to do it, poor you :P
14 15 16 |
# File 'lib/mutx/tasks/task.rb', line 14 def custom_params @custom_params end |
#fr ⇒ Object
Task means what a user can Run. It coul be a test or a tests suites according to the test organization and the used framework There are two types of task: A task properly said and a test. A platform can be specified. It could be one of following:
"bash" => Aimed to run bash commands
"ruby" => When you want to run ruby code
"java" => Well, if you wanto to do it, poor you :P
14 15 16 |
# File 'lib/mutx/tasks/task.rb', line 14 def fr @fr end |
#framework ⇒ Object
Task means what a user can Run. It coul be a test or a tests suites according to the test organization and the used framework There are two types of task: A task properly said and a test. A platform can be specified. It could be one of following:
"bash" => Aimed to run bash commands
"ruby" => When you want to run ruby code
"java" => Well, if you wanto to do it, poor you :P
14 15 16 |
# File 'lib/mutx/tasks/task.rb', line 14 def framework @framework end |
#id ⇒ Object
Task means what a user can Run. It coul be a test or a tests suites according to the test organization and the used framework There are two types of task: A task properly said and a test. A platform can be specified. It could be one of following:
"bash" => Aimed to run bash commands
"ruby" => When you want to run ruby code
"java" => Well, if you wanto to do it, poor you :P
14 15 16 |
# File 'lib/mutx/tasks/task.rb', line 14 def id @id end |
#information ⇒ Object
Task means what a user can Run. It coul be a test or a tests suites according to the test organization and the used framework There are two types of task: A task properly said and a test. A platform can be specified. It could be one of following:
"bash" => Aimed to run bash commands
"ruby" => When you want to run ruby code
"java" => Well, if you wanto to do it, poor you :P
14 15 16 |
# File 'lib/mutx/tasks/task.rb', line 14 def information @information end |
#last_exec_time ⇒ Object
Task means what a user can Run. It coul be a test or a tests suites according to the test organization and the used framework There are two types of task: A task properly said and a test. A platform can be specified. It could be one of following:
"bash" => Aimed to run bash commands
"ruby" => When you want to run ruby code
"java" => Well, if you wanto to do it, poor you :P
14 15 16 |
# File 'lib/mutx/tasks/task.rb', line 14 def last_exec_time @last_exec_time end |
#mail ⇒ Object
Task means what a user can Run. It coul be a test or a tests suites according to the test organization and the used framework There are two types of task: A task properly said and a test. A platform can be specified. It could be one of following:
"bash" => Aimed to run bash commands
"ruby" => When you want to run ruby code
"java" => Well, if you wanto to do it, poor you :P
14 15 16 |
# File 'lib/mutx/tasks/task.rb', line 14 def mail @mail end |
#max_execs ⇒ Object
Task means what a user can Run. It coul be a test or a tests suites according to the test organization and the used framework There are two types of task: A task properly said and a test. A platform can be specified. It could be one of following:
"bash" => Aimed to run bash commands
"ruby" => When you want to run ruby code
"java" => Well, if you wanto to do it, poor you :P
14 15 16 |
# File 'lib/mutx/tasks/task.rb', line 14 def max_execs @max_execs end |
#mo ⇒ Object
Task means what a user can Run. It coul be a test or a tests suites according to the test organization and the used framework There are two types of task: A task properly said and a test. A platform can be specified. It could be one of following:
"bash" => Aimed to run bash commands
"ruby" => When you want to run ruby code
"java" => Well, if you wanto to do it, poor you :P
14 15 16 |
# File 'lib/mutx/tasks/task.rb', line 14 def mo @mo end |
#name ⇒ Object
Task means what a user can Run. It coul be a test or a tests suites according to the test organization and the used framework There are two types of task: A task properly said and a test. A platform can be specified. It could be one of following:
"bash" => Aimed to run bash commands
"ruby" => When you want to run ruby code
"java" => Well, if you wanto to do it, poor you :P
14 15 16 |
# File 'lib/mutx/tasks/task.rb', line 14 def name @name end |
#notifications ⇒ Object
Task means what a user can Run. It coul be a test or a tests suites according to the test organization and the used framework There are two types of task: A task properly said and a test. A platform can be specified. It could be one of following:
"bash" => Aimed to run bash commands
"ruby" => When you want to run ruby code
"java" => Well, if you wanto to do it, poor you :P
14 15 16 |
# File 'lib/mutx/tasks/task.rb', line 14 def notifications @notifications end |
#notify_on ⇒ Object
Task means what a user can Run. It coul be a test or a tests suites according to the test organization and the used framework There are two types of task: A task properly said and a test. A platform can be specified. It could be one of following:
"bash" => Aimed to run bash commands
"ruby" => When you want to run ruby code
"java" => Well, if you wanto to do it, poor you :P
14 15 16 |
# File 'lib/mutx/tasks/task.rb', line 14 def notify_on @notify_on end |
#platform ⇒ Object
Task means what a user can Run. It coul be a test or a tests suites according to the test organization and the used framework There are two types of task: A task properly said and a test. A platform can be specified. It could be one of following:
"bash" => Aimed to run bash commands
"ruby" => When you want to run ruby code
"java" => Well, if you wanto to do it, poor you :P
14 15 16 |
# File 'lib/mutx/tasks/task.rb', line 14 def platform @platform end |
#regex ⇒ Object
Task means what a user can Run. It coul be a test or a tests suites according to the test organization and the used framework There are two types of task: A task properly said and a test. A platform can be specified. It could be one of following:
"bash" => Aimed to run bash commands
"ruby" => When you want to run ruby code
"java" => Well, if you wanto to do it, poor you :P
14 15 16 |
# File 'lib/mutx/tasks/task.rb', line 14 def regex @regex end |
#running_execs ⇒ Object
Task means what a user can Run. It coul be a test or a tests suites according to the test organization and the used framework There are two types of task: A task properly said and a test. A platform can be specified. It could be one of following:
"bash" => Aimed to run bash commands
"ruby" => When you want to run ruby code
"java" => Well, if you wanto to do it, poor you :P
14 15 16 |
# File 'lib/mutx/tasks/task.rb', line 14 def running_execs @running_execs end |
#sa ⇒ Object
Task means what a user can Run. It coul be a test or a tests suites according to the test organization and the used framework There are two types of task: A task properly said and a test. A platform can be specified. It could be one of following:
"bash" => Aimed to run bash commands
"ruby" => When you want to run ruby code
"java" => Well, if you wanto to do it, poor you :P
14 15 16 |
# File 'lib/mutx/tasks/task.rb', line 14 def sa @sa end |
#start_time ⇒ Object
Task means what a user can Run. It coul be a test or a tests suites according to the test organization and the used framework There are two types of task: A task properly said and a test. A platform can be specified. It could be one of following:
"bash" => Aimed to run bash commands
"ruby" => When you want to run ruby code
"java" => Well, if you wanto to do it, poor you :P
14 15 16 |
# File 'lib/mutx/tasks/task.rb', line 14 def start_time @start_time end |
#stop_bots ⇒ Object
Task means what a user can Run. It coul be a test or a tests suites according to the test organization and the used framework There are two types of task: A task properly said and a test. A platform can be specified. It could be one of following:
"bash" => Aimed to run bash commands
"ruby" => When you want to run ruby code
"java" => Well, if you wanto to do it, poor you :P
14 15 16 |
# File 'lib/mutx/tasks/task.rb', line 14 def stop_bots @stop_bots end |
#stop_time ⇒ Object
Task means what a user can Run. It coul be a test or a tests suites according to the test organization and the used framework There are two types of task: A task properly said and a test. A platform can be specified. It could be one of following:
"bash" => Aimed to run bash commands
"ruby" => When you want to run ruby code
"java" => Well, if you wanto to do it, poor you :P
14 15 16 |
# File 'lib/mutx/tasks/task.rb', line 14 def stop_time @stop_time end |
#su ⇒ Object
Task means what a user can Run. It coul be a test or a tests suites according to the test organization and the used framework There are two types of task: A task properly said and a test. A platform can be specified. It could be one of following:
"bash" => Aimed to run bash commands
"ruby" => When you want to run ruby code
"java" => Well, if you wanto to do it, poor you :P
14 15 16 |
# File 'lib/mutx/tasks/task.rb', line 14 def su @su end |
#subject ⇒ Object
Task means what a user can Run. It coul be a test or a tests suites according to the test organization and the used framework There are two types of task: A task properly said and a test. A platform can be specified. It could be one of following:
"bash" => Aimed to run bash commands
"ruby" => When you want to run ruby code
"java" => Well, if you wanto to do it, poor you :P
14 15 16 |
# File 'lib/mutx/tasks/task.rb', line 14 def subject @subject end |
#th ⇒ Object
Task means what a user can Run. It coul be a test or a tests suites according to the test organization and the used framework There are two types of task: A task properly said and a test. A platform can be specified. It could be one of following:
"bash" => Aimed to run bash commands
"ruby" => When you want to run ruby code
"java" => Well, if you wanto to do it, poor you :P
14 15 16 |
# File 'lib/mutx/tasks/task.rb', line 14 def th @th end |
#tu ⇒ Object
Task means what a user can Run. It coul be a test or a tests suites according to the test organization and the used framework There are two types of task: A task properly said and a test. A platform can be specified. It could be one of following:
"bash" => Aimed to run bash commands
"ruby" => When you want to run ruby code
"java" => Well, if you wanto to do it, poor you :P
14 15 16 |
# File 'lib/mutx/tasks/task.rb', line 14 def tu @tu end |
#type ⇒ Object
Task means what a user can Run. It coul be a test or a tests suites according to the test organization and the used framework There are two types of task: A task properly said and a test. A platform can be specified. It could be one of following:
"bash" => Aimed to run bash commands
"ruby" => When you want to run ruby code
"java" => Well, if you wanto to do it, poor you :P
14 15 16 |
# File 'lib/mutx/tasks/task.rb', line 14 def type @type end |
#value_for_regex ⇒ Object
Task means what a user can Run. It coul be a test or a tests suites according to the test organization and the used framework There are two types of task: A task properly said and a test. A platform can be specified. It could be one of following:
"bash" => Aimed to run bash commands
"ruby" => When you want to run ruby code
"java" => Well, if you wanto to do it, poor you :P
14 15 16 |
# File 'lib/mutx/tasks/task.rb', line 14 def value_for_regex @value_for_regex end |
#we ⇒ Object
Task means what a user can Run. It coul be a test or a tests suites according to the test organization and the used framework There are two types of task: A task properly said and a test. A platform can be specified. It could be one of following:
"bash" => Aimed to run bash commands
"ruby" => When you want to run ruby code
"java" => Well, if you wanto to do it, poor you :P
14 15 16 |
# File 'lib/mutx/tasks/task.rb', line 14 def we @we end |
Class Method Details
.delete_this(data) ⇒ Object
206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/mutx/tasks/task.rb', line 206 def self.delete_this(data) if Mutx::Tasks.exist? data["_id"] if Mutx::Database::MongoConnector.delete_task data["_id"] {action:"delete", success:true, message:"Task #{data['_id']} with name #{data["name"]} deleted"} else {action:"delete", success:false, message:"Could not delete task #{data['_id']} with name #{data["name"]}"} end else {action:"delete", success:false, message:"Could not find task to delete"} end end |
.get(task_id) ⇒ Object
114 115 116 117 118 119 |
# File 'lib/mutx/tasks/task.rb', line 114 def self.get task_id Mutx::Support::Log.debug "Getting task data for [id:#{task_id}]" if Mutx::Support::Log task_data = Mutx::Database::MongoConnector.task_data_for task_id task_data = task_data.to_h if respond_to? :to_h new(task_data) if task_data end |
.get_task_with(name) ⇒ Object
121 122 123 124 125 |
# File 'lib/mutx/tasks/task.rb', line 121 def self.get_task_with name data = Mutx::Database::MongoConnector.task_data_for_name(name) raise Mutx::Error::TaskNotFound, "Could not find data for task with name '#{name}'" if data.nil? self.new(data) end |
.new_task(data) ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/mutx/tasks/task.rb', line 127 def self.new_task(data) Mutx::Support::Log.debug "Defining new task [#{data["name"]}]" if Mutx::Support::Log task_data = { "_id" => Mutx::Database::MongoConnector.generate_id, "name" => data["name"], "command" => data["command"], "type" => data["type"], "platform" => data["platform"], "information" => data["information"], "cucumber" => data["cucumber"], "branch" => Mutx::Support::Git.actual_branch, "max_execs" => (data["max_execs"] = 1 if data["max_execs"].eql? 0), "custom_params" => data["custom_params"], "cronneable" => data["cronneable"], "cron_time" => data["cron_time"], "mail" => data["mail"], "subject" => data["subject"], "notifications" => data["notifications"], "blocked" => data["blocked"], "blocked_stop" => data["blocked_stop"], "last_exec_time" => Time.now.utc, "application" => data["application"], "regex" => data["regex"], "mo" => data["mo"], "tu" => data["tu"], "we" => data["we"], "th" => data["th"], "fr" => data["fr"], "sa" => data["sa"], "su" => data["su"], "start_time" => data["start_time"], "stop_time" => data["stop_time"], "value_for_regex" => data["value_for_regex"], "notify_on" => data["notify_on"], "stop_bots" => data["stop_bots"] } self.new(task_data) end |
.valid_types ⇒ Object
52 53 54 |
# File 'lib/mutx/tasks/task.rb', line 52 def self.valid_types ["task","test"] end |
.validate(data) ⇒ Object
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/mutx/tasks/task.rb', line 178 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_value_for_regex(data['value_for_regex'], data['regex'], data['cucumber']) errors << self.validate_notifications(data['notify_on'], data['notifications'], data['mail']) errors << self.validate_max_execs(data["max_execs"]) errors << self.validate_type(data["type"]) errors << self.validate_risk_command(data["command"]) errors.compact end |
.validate_and_create(data) ⇒ Object
167 168 169 170 171 172 173 174 175 176 |
# File 'lib/mutx/tasks/task.rb', line 167 def self.validate_and_create(data) errors = self.validate(data) return { success:false, message:errors.join(" ")} unless errors.empty? if self.new_task(data) {action:"create", success:true, message:"#{data['type'].capitalize} #{data["name"]} created"} else {action:"create", success:false, message:"#{data['type'].capitalize} #{data["name"]} could not be created"} end end |
.validate_and_update(data) ⇒ Object
194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/mutx/tasks/task.rb', line 194 def self.validate_and_update(data) if Mutx::Tasks.exist? data["_id"] if Mutx::Database::MongoConnector.update_task data {action:"edit", success:true, message:"Task updated"} else {action:"edit", success:false, message:"Could not updated task #{data["name"]}"} end else {action:"edit", success:false, message:"Could not find task to update"} end end |
.validate_max_execs(max_execs) ⇒ Object
max_execs could not be greater than global max exec
232 233 234 |
# File 'lib/mutx/tasks/task.rb', line 232 def self.validate_max_execs max_execs return "Maximum executions cannot be greater than #{Mutx::Support::Configuration.max_execs}" if max_execs > Mutx::Support::Configuration.max_execs end |
.validate_name(name) ⇒ Object
task name must be unique
220 221 222 |
# File 'lib/mutx/tasks/task.rb', line 220 def self.validate_name(name) return "There is another task with '#{name}' name." if Mutx::Tasks.is_there_task_with? name end |
.validate_name_with_id(name, id) ⇒ Object
224 225 226 227 228 229 |
# File 'lib/mutx/tasks/task.rb', line 224 def self.validate_name_with_id(name, id) if Mutx::Tasks.is_there_task_with? name existing_id = Mutx::Tasks.task_id_for name return "There is another task with '#{name}' name." if existing_id != id end end |
.validate_notifications(notify_on = nil, notifications = nil, recipients = nil) ⇒ Object
256 257 258 259 260 261 |
# File 'lib/mutx/tasks/task.rb', line 256 def self.validate_notifications notify_on=nil, notifications=nil, recipients=nil if notifications return "Must define at least one recipient to notify" if recipients.nil? return "Invalid value for notify on #{notify_on}" if !NOTIFY_VALID_VALUES.include? notify_on end end |
.validate_risk_command(command) ⇒ Object
command must be evaluated for risks
242 243 244 |
# File 'lib/mutx/tasks/task.rb', line 242 def self.validate_risk_command command return "Your commands seems to be unsecure" unless Mutx::Support::Risk.secure? command end |
.validate_type(type) ⇒ Object
type could be only task or test
237 238 239 |
# File 'lib/mutx/tasks/task.rb', line 237 def self.validate_type type return "#{type} type is not permited." unless self.valid_types.include? type end |
.validate_value_for_regex(value_for_regex = nil, regex = nil, cucumber = nil) ⇒ Object
246 247 248 249 250 251 252 253 254 |
# File 'lib/mutx/tasks/task.rb', line 246 def self.validate_value_for_regex value_for_regex=nil, regex=nil, cucumber=nil regex = nil if regex == "" unless cucumber if regex return "Must define a result for regex" if value_for_regex.nil? return "Invalid value for regex #{value_for_regex}" unless REGEX_VALID_VALUES.include? value_for_regex end end end |
Instance Method Details
#all_results ⇒ Object
342 343 344 |
# File 'lib/mutx/tasks/task.rb', line 342 def all_results Mutx::Database::MongoConnector.results_for(id) end |
#all_results_ids ⇒ Object
338 339 340 |
# File 'lib/mutx/tasks/task.rb', line 338 def all_results_ids all_results.inject([]){|res, result| res << result["_id"]} end |
#api_response ⇒ Object
104 105 106 107 108 109 110 111 112 |
# File 'lib/mutx/tasks/task.rb', line 104 def api_response response = task_data_structure response["results"]={ "size" => number_of_results, "ids" => all_results_ids, "status" => status } response end |
#delete_exec(result_id) ⇒ Object
325 326 327 328 |
# File 'lib/mutx/tasks/task.rb', line 325 def delete_exec result_id @running_execs.delete result_id self.save! end |
#has_custom_params? ⇒ Boolean
307 308 309 |
# File 'lib/mutx/tasks/task.rb', line 307 def has_custom_params? !@custom_params.empty? end |
#has_info? ⇒ Boolean
312 313 314 |
# File 'lib/mutx/tasks/task.rb', line 312 def has_info? not @information.empty? end |
#has_results? ⇒ Boolean
346 347 348 |
# File 'lib/mutx/tasks/task.rb', line 346 def has_results? number_of_results > 0 end |
#number_of_results ⇒ Object
330 331 332 |
# File 'lib/mutx/tasks/task.rb', line 330 def number_of_results all_results.size end |
#number_of_running_results ⇒ Object
334 335 336 |
# File 'lib/mutx/tasks/task.rb', line 334 def number_of_running_results all_results.select{|res| res["status"] == "RUNNING"}.size end |
#push_exec(result_id) ⇒ Object
320 321 322 323 |
# File 'lib/mutx/tasks/task.rb', line 320 def push_exec result_id @running_execs << result_id self.save! end |
#save! ⇒ Object
358 359 360 361 362 363 364 365 |
# File 'lib/mutx/tasks/task.rb', line 358 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 |
#status ⇒ Object
350 351 352 353 354 355 356 |
# File 'lib/mutx/tasks/task.rb', line 350 def status if number_of_running_results > 0 "RUNNING" else "IDLE" end end |
#task_data_for(task_name) ⇒ Object
263 264 265 |
# File 'lib/mutx/tasks/task.rb', line 263 def task_data_for task_name Mutx::Database::MongoConnector.task_data_for(task_name) end |
#task_data_structure ⇒ Hash
Returns the structure of a task data
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 |
# File 'lib/mutx/tasks/task.rb', line 269 def task_data_structure { "_id" => id, "name" => name, "branch" => branch, "type" => type, "command" => command, "custom_params" => custom_params, "information" => information, "running_execs" => running_execs, "max_execs" => max_execs, "cucumber" => cucumber, "platform" => platform, "cronneable" => cronneable, "mail" => mail, "subject" => subject, "notifications" => notifications, "blocked" => blocked, "blocked_stop" => blocked_stop, "cron_time" => cron_time, "last_exec_time" => last_exec_time, "application" => application, "regex" => regex, "mo" => mo, "tu" => tu, "we" => we, "th" => th, "fr" => fr, "sa" => sa, "su" => su, "start_time" => start_time, "stop_time" => stop_time, "value_for_regex" => value_for_regex, "notify_on" => notify_on, "stop_bots" => stop_bots } end |
#test? ⇒ Boolean
316 317 318 |
# File 'lib/mutx/tasks/task.rb', line 316 def test? self.type == "test" end |