Class: Optimal::CI::Queue
- Inherits:
-
Object
- Object
- Optimal::CI::Queue
- Defined in:
- lib/optimal/ci/queue.rb
Instance Method Summary collapse
-
#initialize(provider, command_arguments_string = "") ⇒ Queue
constructor
A new instance of Queue.
- #pop ⇒ Object
- #push(files) ⇒ Object
- #report_duration(duration) ⇒ Object
- #report_http_calls ⇒ Object
Constructor Details
#initialize(provider, command_arguments_string = "") ⇒ Queue
Returns a new instance of Queue.
4 5 6 7 8 9 10 11 12 |
# File 'lib/optimal/ci/queue.rb', line 4 def initialize(provider, command_arguments_string = "") @provider = provider @command_arguments_string = command_arguments_string @http_calls_count = 0 @http_calls_time = 0.0 raise "OPTIMAL_CI_URL is not valid ENV" if ENV['OPTIMAL_CI_URL'].nil? raise "OPTIMAL_CI_TOKEN is not valid ENV" if ENV['OPTIMAL_CI_TOKEN'].nil? end |
Instance Method Details
#pop ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/optimal/ci/queue.rb', line 30 def pop start = Time.now response = ::RestClient.get(ENV['OPTIMAL_CI_URL'] + "/builds/#{@provider.build_number}/get_one_file", { Authorization: ENV['OPTIMAL_CI_TOKEN'] }) @http_calls_count += 1 @http_calls_time += (Time.now - start).to_f return if response.code != 200 JSON.parse(response.body) rescue RestClient::NotFound return nil end |
#push(files) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/optimal/ci/queue.rb', line 14 def push(files) params = { build_number: @provider.build_number, total_files: files, ci: @provider.name, command_arguments_string: @command_arguments_string, total_nodes: @provider.total_nodes } response = ::RestClient.post(ENV['OPTIMAL_CI_URL'] + '/builds', params, { Authorization: ENV['OPTIMAL_CI_TOKEN'] }) response.code == 204 rescue RestClient::Conflict true end |
#report_duration(duration) ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/optimal/ci/queue.rb', line 45 def report_duration(duration) params = { duration: duration, node_index: @provider.node_index } ::RestClient.patch(ENV['OPTIMAL_CI_URL'] + "/builds/#{@provider.build_number}/report_duration", params, { Authorization: ENV['OPTIMAL_CI_TOKEN'] }) end |
#report_http_calls ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/optimal/ci/queue.rb', line 54 def report_http_calls params = { http_calls_count: @http_calls_count, http_calls_time: @http_calls_time, node_index: @provider.node_index } ::RestClient.patch(ENV['OPTIMAL_CI_URL'] + "/builds/#{@provider.build_number}/report_http_calls", params, { Authorization: ENV['OPTIMAL_CI_TOKEN'] }) end |