Class: Mutx::Tasks::Task

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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



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
# File 'lib/mutx/tasks/task.rb', line 59

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"] if (task_data["information"] and 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"]
    @task_status      = task_data["task_status"] || "off"
  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

#applicationObject

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

#blockedObject

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_stopObject

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

#branchObject

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

#commandObject

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_timeObject

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

#cronneableObject

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

#cucumberObject

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_paramsObject

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

#frObject

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

#frameworkObject

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

#idObject

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

#informationObject

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_timeObject

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

#mailObject

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_execsObject

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

#moObject

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

#nameObject

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

#notificationsObject

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_onObject

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

#platformObject

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

#regexObject

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_execsObject

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

#saObject

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_timeObject

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_botsObject

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_timeObject

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

#suObject

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

#subjectObject

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

#task_statusObject

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 task_status
  @task_status
end

#thObject

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

#tuObject

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

#typeObject

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_regexObject

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

#weObject

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



209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/mutx/tasks/task.rb', line 209

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



116
117
118
119
120
121
# File 'lib/mutx/tasks/task.rb', line 116

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



123
124
125
126
127
# File 'lib/mutx/tasks/task.rb', line 123

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



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
166
167
168
# File 'lib/mutx/tasks/task.rb', line 129

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"],
    "task_status" => data["task_status"]
  }
  self.new(task_data)
end

.valid_typesObject



53
54
55
# File 'lib/mutx/tasks/task.rb', line 53

def self.valid_types
  ["task","test"]
end

.validate(data) ⇒ Object



181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/mutx/tasks/task.rb', line 181

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



170
171
172
173
174
175
176
177
178
179
# File 'lib/mutx/tasks/task.rb', line 170

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



197
198
199
200
201
202
203
204
205
206
207
# File 'lib/mutx/tasks/task.rb', line 197

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



235
236
237
# File 'lib/mutx/tasks/task.rb', line 235

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



223
224
225
# File 'lib/mutx/tasks/task.rb', line 223

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



227
228
229
230
231
232
# File 'lib/mutx/tasks/task.rb', line 227

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



259
260
261
262
263
264
# File 'lib/mutx/tasks/task.rb', line 259

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



245
246
247
# File 'lib/mutx/tasks/task.rb', line 245

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



240
241
242
# File 'lib/mutx/tasks/task.rb', line 240

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



249
250
251
252
253
254
255
256
257
# File 'lib/mutx/tasks/task.rb', line 249

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_resultsObject



352
353
354
# File 'lib/mutx/tasks/task.rb', line 352

def all_results
  Mutx::Database::MongoConnector.results_for(id)
end

#all_results_idsObject



348
349
350
# File 'lib/mutx/tasks/task.rb', line 348

def all_results_ids
  all_results.inject([]){|res, result| res << result["_id"]}
end

#api_responseObject



106
107
108
109
110
111
112
113
114
# File 'lib/mutx/tasks/task.rb', line 106

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



335
336
337
338
# File 'lib/mutx/tasks/task.rb', line 335

def delete_exec result_id
  @running_execs.delete result_id
  self.save!
end

#has_custom_params?Boolean

Returns:

  • (Boolean)


317
318
319
# File 'lib/mutx/tasks/task.rb', line 317

def has_custom_params?
  !@custom_params.empty?
end

#has_info?Boolean

Returns:

  • (Boolean)


322
323
324
# File 'lib/mutx/tasks/task.rb', line 322

def has_info?
  not @information.empty?
end

#has_results?Boolean

Returns:

  • (Boolean)


356
357
358
# File 'lib/mutx/tasks/task.rb', line 356

def has_results?
  number_of_results > 0
end

#number_of_resultsObject



340
341
342
# File 'lib/mutx/tasks/task.rb', line 340

def number_of_results
  all_results.size
end

#number_of_running_resultsObject



344
345
346
# File 'lib/mutx/tasks/task.rb', line 344

def number_of_running_results
  all_results.select{|res| res["status"] == "RUNNING"}.size
end

#push_exec!(result_id) ⇒ Object



330
331
332
333
# File 'lib/mutx/tasks/task.rb', line 330

def push_exec! result_id
  @running_execs << result_id
  self.save!
end

#save!Object



368
369
370
371
372
373
374
375
# File 'lib/mutx/tasks/task.rb', line 368

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

#statusObject



360
361
362
363
364
365
366
# File 'lib/mutx/tasks/task.rb', line 360

def status
  if number_of_running_results > 0
    "RUNNING"
  else
    "IDLE"
  end
end

#switch!Object



266
267
268
269
270
# File 'lib/mutx/tasks/task.rb', line 266

def switch!
  @task_status = @task_status == "on" ? "off" : "on"
  self.save!
  @task_status
end

#task_data_for(task_name) ⇒ Object



272
273
274
# File 'lib/mutx/tasks/task.rb', line 272

def task_data_for task_name
  Mutx::Database::MongoConnector.task_data_for(task_name)
end

#task_data_structureHash

Returns the structure of a task data

Returns:

  • (Hash)

    data structure



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
306
307
308
309
310
311
312
313
314
315
# File 'lib/mutx/tasks/task.rb', line 278

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,
    "task_status" => task_status          
  }
end

#test?Boolean

Returns:

  • (Boolean)


326
327
328
# File 'lib/mutx/tasks/task.rb', line 326

def test?
  self.type == "test"
end