From 75ad635f21a463e93ec64ad333c92b70170fbb37 Mon Sep 17 00:00:00 2001 From: Callie Bensel Date: Thu, 1 Apr 2021 10:37:54 -0500 Subject: [PATCH 1/8] CH18616/Update creative template tests to add AdQuery --- test/creative_template_spec.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/creative_template_spec.rb b/test/creative_template_spec.rb index 2bc45f9..8c04e4c 100644 --- a/test/creative_template_spec.rb +++ b/test/creative_template_spec.rb @@ -17,12 +17,14 @@ type: 'String', variable: 'ctTitle', required: true, + ad_query: false }, { name: 'Thumbnail', description: 'The URL of a Thumbnail Image', type: 'String', variable: 'ctThumbnailUrl', required: false, + ad_query: true }], contents: [{ type: 'Raw', @@ -60,12 +62,14 @@ type: 'String', variable: 'ctTitle', required: true, + ad_query: false, }, { name: 'Thumbnail', description: 'The URL of a Thumbnail Image', type: 'String', variable: 'ctThumbnailUrl', required: false, + ad_query: true, }], contents: [{ type: 'Raw', From a13e4a651b88f7e24099dfa92ad88750eaa100b7 Mon Sep 17 00:00:00 2001 From: Justin Niessner Date: Fri, 26 Mar 2021 16:37:11 -0400 Subject: [PATCH 2/8] CH16251: Naive Backoff/Jitter attempt --- lib/adzerk/client.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/adzerk/client.rb b/lib/adzerk/client.rb index 0285afc..63ae443 100644 --- a/lib/adzerk/client.rb +++ b/lib/adzerk/client.rb @@ -12,6 +12,8 @@ class Client VERSION = Gem.loaded_specs['adzerk'].version.to_s SDK_HEADER_NAME = 'X-Adzerk-Sdk-Version' SDK_HEADER_VALUE = "adzerk-management-sdk-ruby:#{VERSION}" + BASE_SLEEP = 0.25 + MAX_SLEEP = 5 DEFAULTS = { :host => ENV["ADZERK_API_HOST"] || 'https://api.adzerk.net/', @@ -111,9 +113,17 @@ def upload_creative(id, image_path, size_override: false, version: 'v1') end def send_request(request, uri) + attempt = 0 http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = uri.scheme == 'https' - response = http.request(request) + + loop do + response = http.request(request) + break if response.code != "429" + sleep(rand(0.0..[MAX_SLEEP, BASE_SLEEP * 2 ** attempt])) + attempt++ + end + if response.kind_of? Net::HTTPClientError or response.kind_of? Net::HTTPServerError error_response = JSON.parse(response.body) msg = error_response["message"] || error_response["Error"] || response.body From 9b63c99a8836c66903d8ddf3bb5933b03835fb29 Mon Sep 17 00:00:00 2001 From: Justin Niessner Date: Fri, 26 Mar 2021 16:56:27 -0400 Subject: [PATCH 3/8] CH16251: Add more backoff/retry --- lib/adzerk/client.rb | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/lib/adzerk/client.rb b/lib/adzerk/client.rb index 63ae443..3da05b4 100644 --- a/lib/adzerk/client.rb +++ b/lib/adzerk/client.rb @@ -92,27 +92,45 @@ def put_json_request(url, data, version: 'v1') end def create_creative(data={}, image_path='', version: 'v1') - response = RestClient.post(@config[:host] + version + '/creative', - {:creative => camelize_data(data).to_json}, - :X_Adzerk_ApiKey => @api_key, - :X_Adzerk_Sdk_Version => SDK_HEADER_VALUE, - :accept => :json) + response = nil + attempt = 0 + + loop do + response = RestClient.post(@config[:host] + version + '/creative', + {:creative => camelize_data(data).to_json}, + :X_Adzerk_ApiKey => @api_key, + :X_Adzerk_Sdk_Version => SDK_HEADER_VALUE, + :accept => :json) + break if response.code != 429 + sleep(rand(0.0..[MAX_SLEEP, BASE_SLEEP * 2 ** attempt])) + attempt += 1 + end response = upload_creative(JSON.parse(response)["Id"], image_path) unless image_path.empty? response end def upload_creative(id, image_path, size_override: false, version: 'v1') + response = nil + attempt = 0 image = File.new(image_path, 'rb') url = @config[:host] + version + '/creative/' + id.to_s + '/upload' url += '?sizeOverride=true' if size_override - RestClient.post(url, - {:image => image}, - "X-Adzerk-ApiKey" => @api_key, - SDK_HEADER_NAME => SDK_HEADER_VALUE, - :accept => :mime) + loop do + response = RestClient.post(url, + {:image => image}, + "X-Adzerk-ApiKey" => @api_key, + SDK_HEADER_NAME => SDK_HEADER_VALUE, + :accept => :mime) + + break if response.code != 429 + sleep(rand(0.0..[MAX_SLEEP, BASE_SLEEP * 2 ** attempt])) + attempt += 1 + end + response end def send_request(request, uri) + response = nil attempt = 0 http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = uri.scheme == 'https' @@ -121,7 +139,7 @@ def send_request(request, uri) response = http.request(request) break if response.code != "429" sleep(rand(0.0..[MAX_SLEEP, BASE_SLEEP * 2 ** attempt])) - attempt++ + attempt += 1 end if response.kind_of? Net::HTTPClientError or response.kind_of? Net::HTTPServerError @@ -129,6 +147,7 @@ def send_request(request, uri) msg = error_response["message"] || error_response["Error"] || response.body raise Adzerk::ApiError.new(msg) end + response end From dad6b206a494434e21a21497fa1d255fd0c19a0a Mon Sep 17 00:00:00 2001 From: Justin Niessner Date: Thu, 1 Apr 2021 12:00:38 -0400 Subject: [PATCH 4/8] CH16251: Add max attempts check --- lib/adzerk/client.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/adzerk/client.rb b/lib/adzerk/client.rb index 3da05b4..839583c 100644 --- a/lib/adzerk/client.rb +++ b/lib/adzerk/client.rb @@ -14,6 +14,7 @@ class Client SDK_HEADER_VALUE = "adzerk-management-sdk-ruby:#{VERSION}" BASE_SLEEP = 0.25 MAX_SLEEP = 5 + MAX_ATTEMPTS = 10 DEFAULTS = { :host => ENV["ADZERK_API_HOST"] || 'https://api.adzerk.net/', @@ -101,7 +102,7 @@ def create_creative(data={}, image_path='', version: 'v1') :X_Adzerk_ApiKey => @api_key, :X_Adzerk_Sdk_Version => SDK_HEADER_VALUE, :accept => :json) - break if response.code != 429 + break if response.code != 429 or attempt >= MAX_ATTEMPTS sleep(rand(0.0..[MAX_SLEEP, BASE_SLEEP * 2 ** attempt])) attempt += 1 end @@ -122,7 +123,7 @@ def upload_creative(id, image_path, size_override: false, version: 'v1') SDK_HEADER_NAME => SDK_HEADER_VALUE, :accept => :mime) - break if response.code != 429 + break if response.code != 429 or attempt >= MAX_ATTEMPTS sleep(rand(0.0..[MAX_SLEEP, BASE_SLEEP * 2 ** attempt])) attempt += 1 end @@ -137,7 +138,7 @@ def send_request(request, uri) loop do response = http.request(request) - break if response.code != "429" + break if response.code != "429" or attempt >= MAX_ATTEMPTS sleep(rand(0.0..[MAX_SLEEP, BASE_SLEEP * 2 ** attempt])) attempt += 1 end From 4ea2c85b509572379cc3a0abc607ea1280c8ea48 Mon Sep 17 00:00:00 2001 From: Justin Niessner Date: Fri, 9 Apr 2021 14:09:51 -0400 Subject: [PATCH 5/8] CH16251: Actually call min on rand params --- lib/adzerk/client.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/adzerk/client.rb b/lib/adzerk/client.rb index 839583c..6241a8f 100644 --- a/lib/adzerk/client.rb +++ b/lib/adzerk/client.rb @@ -103,7 +103,7 @@ def create_creative(data={}, image_path='', version: 'v1') :X_Adzerk_Sdk_Version => SDK_HEADER_VALUE, :accept => :json) break if response.code != 429 or attempt >= MAX_ATTEMPTS - sleep(rand(0.0..[MAX_SLEEP, BASE_SLEEP * 2 ** attempt])) + sleep(rand(0.0..[MAX_SLEEP, BASE_SLEEP * 2 ** attempt].min())) attempt += 1 end response = upload_creative(JSON.parse(response)["Id"], image_path) unless image_path.empty? @@ -124,7 +124,7 @@ def upload_creative(id, image_path, size_override: false, version: 'v1') :accept => :mime) break if response.code != 429 or attempt >= MAX_ATTEMPTS - sleep(rand(0.0..[MAX_SLEEP, BASE_SLEEP * 2 ** attempt])) + sleep(rand(0.0..[MAX_SLEEP, BASE_SLEEP * 2 ** attempt].min())) attempt += 1 end response @@ -139,7 +139,7 @@ def send_request(request, uri) loop do response = http.request(request) break if response.code != "429" or attempt >= MAX_ATTEMPTS - sleep(rand(0.0..[MAX_SLEEP, BASE_SLEEP * 2 ** attempt])) + sleep(rand(0.0..min([MAX_SLEEP, BASE_SLEEP * 2 ** attempt].min()))) attempt += 1 end From cdbbccc7bb79a0a94f6ace98b785f0072c9d5e90 Mon Sep 17 00:00:00 2001 From: Justin Niessner Date: Fri, 9 Apr 2021 14:12:38 -0400 Subject: [PATCH 6/8] CH16251: Remove bad chars --- lib/adzerk/client.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/adzerk/client.rb b/lib/adzerk/client.rb index 6241a8f..3df9fdb 100644 --- a/lib/adzerk/client.rb +++ b/lib/adzerk/client.rb @@ -139,7 +139,7 @@ def send_request(request, uri) loop do response = http.request(request) break if response.code != "429" or attempt >= MAX_ATTEMPTS - sleep(rand(0.0..min([MAX_SLEEP, BASE_SLEEP * 2 ** attempt].min()))) + sleep(rand(0.0..[MAX_SLEEP, BASE_SLEEP * 2 ** attempt].min())) attempt += 1 end From 6f6ea97afc4f8631df32fbf062ae98f5d9b18a6d Mon Sep 17 00:00:00 2001 From: Justin Niessner Date: Fri, 9 Apr 2021 14:37:46 -0400 Subject: [PATCH 7/8] Disable all CI --- .github/workflows/ruby.yml | 80 +++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 0da339d..549e08a 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -1,46 +1,46 @@ -name: Ruby +# name: Ruby -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] - schedule: - - cron: "0 9 * * 4" +# on: +# push: +# branches: [ master ] +# pull_request: +# branches: [ master ] +# schedule: +# - cron: "0 9 * * 4" -jobs: - test: +# jobs: +# test: - runs-on: ubuntu-latest +# runs-on: ubuntu-latest - strategy: - max-parallel: 1 - matrix: - ruby-version: [2.5.7, 2.6, 2.7.0, 3.0.0] +# strategy: +# max-parallel: 1 +# matrix: +# ruby-version: [2.5.7, 2.6, 2.7.0, 3.0.0] - steps: - - uses: actions/checkout@v2 - - name: Set up Ruby - # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby, - # change this to (see https://github.com/ruby/setup-ruby#versioning): - uses: ruby/setup-ruby@v1 - with: - ruby-version: ${{ matrix.ruby-version }} - - name: Install dependencies - run: bundle install - - name: Run tests - env: - ADZERK_API_KEY: ${{ secrets.ADZERK_API_KEY }} - run: bundle exec rake +# steps: +# - uses: actions/checkout@v2 +# - name: Set up Ruby +# # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby, +# # change this to (see https://github.com/ruby/setup-ruby#versioning): +# uses: ruby/setup-ruby@v1 +# with: +# ruby-version: ${{ matrix.ruby-version }} +# - name: Install dependencies +# run: bundle install +# - name: Run tests +# env: +# ADZERK_API_KEY: ${{ secrets.ADZERK_API_KEY }} +# run: bundle exec rake - slack: - needs: test - runs-on: ubuntu-latest - if: always() - steps: - - uses: technote-space/workflow-conclusion-action@v2 - - uses: 8398a7/action-slack@v3 - with: - status: ${{ env.WORKFLOW_CONCLUSION }} - env: - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} \ No newline at end of file +# slack: +# needs: test +# runs-on: ubuntu-latest +# if: always() +# steps: +# - uses: technote-space/workflow-conclusion-action@v2 +# - uses: 8398a7/action-slack@v3 +# with: +# status: ${{ env.WORKFLOW_CONCLUSION }} +# env: +# SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} \ No newline at end of file From 2d8b476a37fe42c95c1c778878e22c3de4f91628 Mon Sep 17 00:00:00 2001 From: Justin Niessner Date: Fri, 9 Apr 2021 14:37:59 -0400 Subject: [PATCH 8/8] CH16251: add max attempts config --- lib/adzerk/client.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/adzerk/client.rb b/lib/adzerk/client.rb index 3df9fdb..03c6fd7 100644 --- a/lib/adzerk/client.rb +++ b/lib/adzerk/client.rb @@ -102,7 +102,7 @@ def create_creative(data={}, image_path='', version: 'v1') :X_Adzerk_ApiKey => @api_key, :X_Adzerk_Sdk_Version => SDK_HEADER_VALUE, :accept => :json) - break if response.code != 429 or attempt >= MAX_ATTEMPTS + break if response.code != 429 or attempt >= (@config[:max_attempts] || MAX_ATTEMPTS) sleep(rand(0.0..[MAX_SLEEP, BASE_SLEEP * 2 ** attempt].min())) attempt += 1 end @@ -123,7 +123,7 @@ def upload_creative(id, image_path, size_override: false, version: 'v1') SDK_HEADER_NAME => SDK_HEADER_VALUE, :accept => :mime) - break if response.code != 429 or attempt >= MAX_ATTEMPTS + break if response.code != 429 or attempt >= (@config[:max_attempts] || MAX_ATTEMPTS) sleep(rand(0.0..[MAX_SLEEP, BASE_SLEEP * 2 ** attempt].min())) attempt += 1 end @@ -138,7 +138,7 @@ def send_request(request, uri) loop do response = http.request(request) - break if response.code != "429" or attempt >= MAX_ATTEMPTS + break if response.code != "429" or attempt >= (@config[:max_attempts] || MAX_ATTEMPTS) sleep(rand(0.0..[MAX_SLEEP, BASE_SLEEP * 2 ** attempt].min())) attempt += 1 end