Class: Mutx::API::Result

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

Class Method Summary collapse

Class Method Details

.data(result_id, query_string = nil) ⇒ Object

query_string is like “first.object.in.a.json”



35
36
37
38
39
40
41
42
# File 'lib/mutx/API/result.rb', line 35

def self.data result_id, query_string=nil
  result = self.info result_id
  if query_string
    {"execution_data" =>Mutx::API::Path.data(result["execution_data"], query_string)}
  else
    {"type" => "result", "_id" => result["_id"], "status" => result["status"], "execution_data" => result["execution_data"]}
  end
end

.get_for_task(task_id) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/mutx/API/result.rb', line 5

def self.get_for_task(task_id)
  task = Mutx::Tasks::Task.get(task_id)
  if task
    {
      "project_name" => Dir.pwd.split("/").last,
      "task" => {id:task.id, name:task.name},
      "results" => results_list_for(task.id)
    }
  else
    {"results" => results_list}
  end
end

.info(result_id) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/mutx/API/result.rb', line 25

def self.info(result_id)
  result = Mutx::Results::Result.get(result_id)
  if result
    result.api_response
  else
    {"message" => "Result #{result_id} not found"}
  end
end

.last_notified(quantity) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/mutx/API/result.rb', line 58

def self.last_notified quantity
  results = []
  result = Mutx::Database::MongoConnector.last_notified quantity
  if result
    result.each do |line|
      new_line = "[***********]\n".concat line["task"]["name"].upcase.concat " => ".concat (Time.at(line["started_at"])).to_s.concat "[***********]\n"
      new_line.slice! "-0300"
      results << new_line
      new_line = nil
    end
    results
    res = results.join(",").gsub(/[,]/, "\n\n")
    res
  else
    "No response to display"
  end
end

.output(result_id) ⇒ Object



49
50
51
52
53
54
55
56
# File 'lib/mutx/API/result.rb', line 49

def self.output result_id
  result = Mutx::Results::Result.get(result_id)
  if result
    result.console_output
  else
    "No content to display"
  end
end

.results_list_for(task_id) ⇒ Object



18
19
20
21
22
23
# File 'lib/mutx/API/result.rb', line 18

def self.results_list_for(task_id)
  task_results = Mutx::Results.results_ids_for(task_id)
  task_results.map do |result_id|
    info(result_id)
  end
end

.status(result_id) ⇒ Object



44
45
46
47
# File 'lib/mutx/API/result.rb', line 44

def self.status result_id
  result = self.info result_id
  {"type" => "result", "status" => result["status"]}
end