Class: JenkinsApi::Client::BuildQueue
- Inherits:
-
Object
- Object
- JenkinsApi::Client::BuildQueue
- Defined in:
- lib/jenkins_api_client/build_queue.rb
Overview
This classes communicates with the Build Queue API exposed by Jenkins at “/queue” that gives information about jobs/tasks in the queue and their details.
Instance Method Summary collapse
-
#get_age(task_name) ⇒ Fixnum
Gets the time number of seconds the task is in the queue.
-
#get_causes(task_name) ⇒ Array
Obtains the causes from the build queue for the specified task.
-
#get_details(task_name) ⇒ Hash
Obtains the detail Hash from the API response.
-
#get_eta(task_name) ⇒ String
Obtains the ETA given by Jenkins if any.
-
#get_id(task_name) ⇒ String
Obtains the ID of the task from the queue.
-
#get_params(task_name) ⇒ String
Obtains the params from the build queue.
-
#get_reason(task_name) ⇒ String
Obtains the reason why the task is in queue.
-
#initialize(client) ⇒ BuildQueue
constructor
Initializes a new BuildQueue object.
-
#is_blocked?(task_name) ⇒ TrueClass|FalseClass
Obtains whether the task is blocked.
-
#is_buildable?(task_name) ⇒ TrueClass|FalseClass
Obtains whether the task is buildable.
-
#is_stuck?(task_name) ⇒ TrueClass|FalseClass
Obtains whether the task is stuck.
-
#list ⇒ Object
Lists all tasks currently in the build queue.
-
#size ⇒ Object
Gives the number of jobs currently in the build queue.
-
#to_s ⇒ Object
Returns a string representation of BuildQueue class.
Constructor Details
#initialize(client) ⇒ BuildQueue
Initializes a new BuildQueue object.
35 36 37 |
# File 'lib/jenkins_api_client/build_queue.rb', line 35 def initialize(client) @client = client end |
Instance Method Details
#get_age(task_name) ⇒ Fixnum
Gets the time number of seconds the task is in the queue
69 70 71 72 73 74 75 76 |
# File 'lib/jenkins_api_client/build_queue.rb', line 69 def get_age(task_name) age = nil details = get_details(task_name) unless details.empty? age = Time.now - Time.at(details["inQueueSince"].to_i/1000) end age end |
#get_causes(task_name) ⇒ Array
Obtains the causes from the build queue for the specified task
99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/jenkins_api_client/build_queue.rb', line 99 def get_causes(task_name) causes = nil details = get_details(task_name) unless details.empty? causes = [] details["actions"].each do |action| causes << action["causes"] end end causes end |
#get_details(task_name) ⇒ Hash
Obtains the detail Hash from the API response
84 85 86 87 88 89 90 91 |
# File 'lib/jenkins_api_client/build_queue.rb', line 84 def get_details(task_name) response_json = @client.api_get_request("/queue") details = {} response_json["items"].each do |item| details = item if item["task"]["name"] end details end |
#get_eta(task_name) ⇒ String
Obtains the ETA given by Jenkins if any
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/jenkins_api_client/build_queue.rb', line 133 def get_eta(task_name) eta = nil details = get_details(task_name) unless details.empty? matched = details["why"].match(/.*\(ETA:(.*)\)/) if matched.nil? # Task is found, but ETA information is not available eta = "N/A" else # ETA information is available eta = matched[1].strip end end eta end |
#get_id(task_name) ⇒ String
Obtains the ID of the task from the queue
155 156 157 158 159 160 161 162 |
# File 'lib/jenkins_api_client/build_queue.rb', line 155 def get_id(task_name) id = nil details = get_details(task_name) unless details.empty? id = details["id"] end id end |
#get_params(task_name) ⇒ String
Obtains the params from the build queue
170 171 172 173 174 175 176 177 |
# File 'lib/jenkins_api_client/build_queue.rb', line 170 def get_params(task_name) params = nil details = get_details(task_name) unless details.empty? params = details["params"] end params end |
#get_reason(task_name) ⇒ String
Obtains the reason why the task is in queue
117 118 119 120 121 122 123 124 |
# File 'lib/jenkins_api_client/build_queue.rb', line 117 def get_reason(task_name) reason = nil details = get_details(task_name) unless details.empty? reason = details["why"] end reason end |
#is_blocked?(task_name) ⇒ TrueClass|FalseClass
Obtains whether the task is blocked
200 201 202 203 204 205 206 207 |
# File 'lib/jenkins_api_client/build_queue.rb', line 200 def is_blocked?(task_name) blocked = nil details = get_details(task_name) unless details.empty? blocked = details["blocked"] end blocked end |
#is_buildable?(task_name) ⇒ TrueClass|FalseClass
Obtains whether the task is buildable
185 186 187 188 189 190 191 192 |
# File 'lib/jenkins_api_client/build_queue.rb', line 185 def is_buildable?(task_name) buildable = nil details = get_details(task_name) unless details.empty? buildable = details["buildable"] end buildable end |
#is_stuck?(task_name) ⇒ TrueClass|FalseClass
Obtains whether the task is stuck
215 216 217 218 219 220 221 222 |
# File 'lib/jenkins_api_client/build_queue.rb', line 215 def is_stuck?(task_name) stuck = nil details = get_details(task_name) unless details.empty? stuck = details["stuck"] end stuck end |
#list ⇒ Object
Lists all tasks currently in the build queue
54 55 56 57 58 59 60 61 |
# File 'lib/jenkins_api_client/build_queue.rb', line 54 def list response_json = @client.api_get_request("/queue") tasks = [] response_json["items"].each do |item| tasks << item["task"]["name"] end tasks end |
#size ⇒ Object
Gives the number of jobs currently in the build queue
47 48 49 50 |
# File 'lib/jenkins_api_client/build_queue.rb', line 47 def size response_json = @client.api_get_request("/queue") response_json["items"].size end |
#to_s ⇒ Object
Returns a string representation of BuildQueue class.
41 42 43 |
# File 'lib/jenkins_api_client/build_queue.rb', line 41 def to_s "#<JenkinsApi::Client::BuildQueue>" end |