Class: Mutx::API::Execution

Inherits:
Object
  • Object
show all
Defined in:
lib/mutx/API/execution.rb

Class Method Summary collapse

Class Method Details

.reset(result_id) ⇒ Object

RESET EXECUTION

Kill associated process to the running execution Sets as finished the result and associated task as READY



100
101
102
103
104
105
106
107
108
109
# File 'lib/mutx/API/execution.rb', line 100

def self.reset(result_id)
  result = Mutx::Results::Result.get(result_id)
    
  message = if result.reset!
    "[#{result.id}] Execution stopped"
  else
    "[#{result.id}] Could not stop execution"
  end
  {"message" => message}
end

.start(task_name, query_string, type = nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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
88
89
90
91
92
93
# File 'lib/mutx/API/execution.rb', line 5

def self.start task_name, query_string, type = nil
  Mutx::Support::Log.debug "Starting task #{task_name}" if Mutx::Support::Log

  git_log = Mutx::Support::Configuration.use_git? ? Mutx::Support::Git.log_last_commit : ""


  unless query_string.empty?

    execution_name = query_string.delete("execution_name") if query_string.has_key? "execution_name"
    query_string.each_pair do |param, value|
      query_string.delete(param) if (value =~ /Enter/ or value.nil? or value == "")
    end
    custom_params = query_string || {}

  else
    execution_name =  nil
    custom_params = {}
  end

  error = false
  
  running_started = []
  running_started = Mutx::Database::MongoConnector.running_for_task task_name

  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

    type = task.type

    if Mutx::Tasks.number_of_running_executions_for_task(task_name) < task.max_execs

      Mutx::Support::Log.debug "#{task.type.capitalize} #{task_name} is ready to run" if Mutx::Support::Log

      execution_request_data = {
        "platform"        => task.platform,
        "task"            => {"id" => task.id, "name" => task.name, "type" => task.type, "cucumber" => task.cucumber, "platform" => task.platform},
        "execution_name"  => execution_name,
        "custom_params"   => custom_params,
        "git_log"         => git_log,
        "started_message" => "#{task.type.capitalize} #{task.name} started"
      }

      execution_id = Mutx::Execution.run!(execution_request_data)

      task.push_exec! execution_id

      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
      Mutx::Support::Log.debug "#{task.type.capitalize} #{task.name} started" if Mutx::Support::Log

    else

      execution_id = nil
      started = false
      status = 423
      message = "Max number of concurrent execution reached.
      Cannot run more than #{task.max_execs} executions simultaneously.
      Please wait until one is finalized"
      Mutx::Support::Log.error "Cannot run more than #{task.max_execs} executions simultaneously" if Mutx::Support::Log
    end

  else # No task for  task_name
    Mutx::Support::Log.error "Task not found for name #{task_name}" if Mutx::Support::Log
    started = false
    execution_id = task_id = nil
    status = 404
    error = true
    message = "Task #{task_name} not found"
  end
    {
      "task" => {
        "name" => task_name,
        "id" => task_id,
        "started" => started,
        "type" => type
        },
      "execution_id" => execution_id,
      "message" => message,
      "error" => error,
      "status" => status
    }
end