Module: Mutx::API::Tasks

Defined in:
lib/mutx/API/tasks.rb

Class Method Summary collapse

Class Method Details

.cron_update(data) ⇒ Object



21
22
23
24
# File 'lib/mutx/API/tasks.rb', line 21

def self.cron_update data
  data = self.sanitize data
  res = Mutx::Tasks::Task.validate_and_update(data)
end

.list(options = {}) ⇒ Object

Parameters:

  • options (hash) (defaults to: {})

    :active, :type



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

def self.list(options ={})

  type = options[:type]

  start = Time.now.to_f

  response = {
    "project_name" => Dir.pwd.split("/").last,
    "size" => 0,
    "type" => type,
    "tasks" => [],
    "message" => nil
  }
  tasks = if options[:running]
    type = options[:type]
    response["request"] = "Running #{type.capitalize}"
    if type == "task"
      Mutx::Tasks.running_tasks
    else
      Mutx::Tasks.running_tests
    end
  else
    response["request"] = options[:type] ? "#{options[:type].capitalize} Tasks" : "Tasks"
    Mutx::Tasks.tasks options[:type]
  end


  if tasks.size.zero?
    response["message"] = options[:running] ? "Running tasks not found" : "Tasks not found"
  else

    tasks = tasks.map do |task|
      results_for_task = Mutx::Results.results_ids_for task["_id"]
      task["results"]={
        "size" => results_for_task.size,
        "ids" => results_for_task
      }
      task
    end

    response["tasks"] = tasks
    Mutx::Support::Log.debug "#{tasks.size} retrieved in (#{Time.now.to_f - start} s)" if Mutx::Support::Log

    response["size"] = tasks.size
  end
  response
end

.sanitize(data) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/mutx/API/tasks.rb', line 26

def self.sanitize data
  data["max_execs"] = data["max_execs"].to_i if data["max_execs"].respond_to? :to_i
  data["cucumber"] = data["cucumber"]
  data["information"] = nil if data["information"].nil?
  data["last_exec_time"] = Time.now.utc
  data["stop_bots"] = data["stop_bots"] 
  if data["task_status"] == "off" 
    data["task_status"] = "off"
  else
    data["task_status"] = "on"
  end
  data
end

.set(data) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/mutx/API/tasks.rb', line 6

def self.set data

  data = self.sanitize data

  response = case data["action"]
  when "new"
    Mutx::Tasks::Task.validate_and_create(data)
  when "edit"
    Mutx::Tasks::Task.validate_and_update(data)
  when "delete"
    Mutx::Tasks::Task.delete_this(data)
  end
  response
end