Class: Hive::Messages::Job
- Includes:
- Representers::JobRepresenter
- Defined in:
- lib/hive/messages/job.rb
Class Method Summary collapse
Instance Method Summary collapse
- #complete ⇒ Object
- #end(exit_value) ⇒ Object
- #error(message) ⇒ Object
- #fetch(uri_str, limit = 10) ⇒ Object
- #prepare(device_id) ⇒ Object
- #report_artifact(artifact_path) ⇒ Object
- #start ⇒ Object
- #update_results(details) ⇒ Object
Class Method Details
.reserve(queues, reservation_details) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/hive/messages/job.rb', line 34 def reserve(queues, reservation_details) job = self.new job.reservation_details = reservation_details begin job.patch(uri: Hive::Paths::Queues.job_reservation_url(queues), as: "application/json") rescue => e Hive::Messages::NilJob.new(e) end end |
Instance Method Details
#complete ⇒ Object
108 109 110 |
# File 'lib/hive/messages/job.rb', line 108 def complete self.patch(uri: Hive::Paths::Jobs.complete_url(self.job_id), as: "application/json") end |
#end(exit_value) ⇒ Object
54 55 56 57 |
# File 'lib/hive/messages/job.rb', line 54 def end(exit_value) self.exit_value = exit_value self.patch(uri: Hive::Paths::Jobs.end_url(self.job_id), as: "application/json") end |
#error(message) ⇒ Object
112 113 114 115 |
# File 'lib/hive/messages/job.rb', line 112 def error() self. = self.patch(uri: Hive::Paths::Jobs.error_url(self.job_id), as: "application/json") end |
#fetch(uri_str, limit = 10) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/hive/messages/job.rb', line 85 def fetch(uri_str, limit = 10) raise ArgumentError, 'too many HTTP redirects' if limit == 0 url = URI.parse(uri_str) net_http_args = http_args(url) request = Net::HTTP::Get.new(url) response = http_response(url, request, net_http_args) case response when Net::HTTPSuccess then response when Net::HTTPRedirection then location = response['location'] warn "redirected to #{location}" fetch(location, limit - 1) when Net::HTTPNotFound then raise "Build not found at location #{uri_str}" else response.value end end |
#prepare(device_id) ⇒ Object
45 46 47 48 |
# File 'lib/hive/messages/job.rb', line 45 def prepare(device_id) self.device_id = device_id self.patch(uri: Hive::Paths::Jobs.prepare_url(self.job_id), as: "application/json") end |
#report_artifact(artifact_path) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/hive/messages/job.rb', line 68 def report_artifact(artifact_path) url = URI.parse(Hive::Paths::Artifacts.create_url(self.job_id)) basename = Pathname.new(artifact_path).basename.to_s mime = MimeMagic.by_path(artifact_path) mime_type = mime ? mime.type : 'text/plain' net_http_args = http_args(url) File.open(artifact_path) do |artifact| request = Net::HTTP::Post::Multipart.new url.path, "data" => UploadIO.new(artifact, mime_type, basename) res = http_response(url, request, net_http_args) Hive::Messages::Artifact.new.from_json(res.body) end end |
#start ⇒ Object
50 51 52 |
# File 'lib/hive/messages/job.rb', line 50 def start self.patch(uri: Hive::Paths::Jobs.start_url(self.job_id), as: "application/json") end |
#update_results(details) ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/hive/messages/job.rb', line 59 def update_results(details) self.result_details = details[:result_details] counts = details.slice(:running_count, :failed_count, :errored_count, :passed_count) counts.each_pair do |count_key, count_value| self.send("#{count_key}=", count_value) end self.patch(uri: Hive::Paths::Jobs.update_results_url(self.job_id), as: "application/json") end |