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
- #prepare(device_id) ⇒ Object
- #report_artifact(artifact_path) ⇒ Object
- #start ⇒ Object
- #update_results(details) ⇒ Object
Class Method Details
.reserve(queues, reservation_details) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/hive/messages/job.rb', line 30 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
90 91 92 |
# File 'lib/hive/messages/job.rb', line 90 def complete self.patch(uri: Hive::Paths::Jobs.complete_url(self.job_id), as: "application/json") end |
#end(exit_value) ⇒ Object
50 51 52 53 |
# File 'lib/hive/messages/job.rb', line 50 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
94 95 96 97 |
# File 'lib/hive/messages/job.rb', line 94 def error() self. = self.patch(uri: Hive::Paths::Jobs.error_url(self.job_id), as: "application/json") end |
#prepare(device_id) ⇒ Object
41 42 43 44 |
# File 'lib/hive/messages/job.rb', line 41 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
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 |
# File 'lib/hive/messages/job.rb', line 64 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 = {:use_ssl => url.instance_of?(URI::HTTPS)} if Hive::Messages.configuration.pem_file pem = File.read(Hive::Messages.configuration.pem_file) net_http_args[:cert] = OpenSSL::X509::Certificate.new(pem) net_http_args[:key] = OpenSSL::PKey::RSA.new(pem) net_http_args[:verify_mode] = Hive::Messages.configuration.ssl_verify_mode end File.open(artifact_path) do |artifact| req = Net::HTTP::Post::Multipart.new url.path, "data" => UploadIO.new(artifact, mime_type, basename) res = Net::HTTP.start(url.host, url.port, net_http_args) do |http| http.request(req) end Hive::Messages::Artifact.new.from_json(res.body) end end |
#start ⇒ Object
46 47 48 |
# File 'lib/hive/messages/job.rb', line 46 def start self.patch(uri: Hive::Paths::Jobs.start_url(self.job_id), as: "application/json") end |
#update_results(details) ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/hive/messages/job.rb', line 55 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 |