Skip to content

Commit

Permalink
cohort not modfied should not throw error
Browse files Browse the repository at this point in the history
  • Loading branch information
tyiuhc committed Jul 31, 2024
1 parent 8fff5fc commit b8ad1ab
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 9 deletions.
5 changes: 3 additions & 2 deletions lib/experiment/cohort/cohort_download_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ def get_cohort(cohort_id, cohort = nil)
cohort_info['groupType']
)
when 204
raise CohortNotModifiedError.new(cohort_id, "Cohort not modified: #{response.code}")
@logger.debug("getCohortMembers(#{cohort_id}): Cohort not modified")
return nil
when 413
raise CohortTooLargeError.new(cohort_id, "Cohort exceeds max cohort size: #{response.code}")
else
Expand All @@ -56,7 +57,7 @@ def get_cohort(cohort_id, cohort = nil)
rescue StandardError => e
errors += 1 unless response && e.is_a?(HTTPErrorResponseError) && response.code.to_i == 429
@logger.debug("getCohortMembers(#{cohort_id}): request-status error #{errors} - #{e}")
raise e if errors >= 3 || e.is_a?(CohortNotModifiedError) || e.is_a?(CohortTooLargeError)
raise e if errors >= 3 || e.is_a?(CohortTooLargeError)
end

sleep(@cohort_request_delay_millis / 1000.0)
Expand Down
2 changes: 1 addition & 1 deletion lib/experiment/cohort/cohort_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def update_stored_cohorts
def load_cohort_internal(cohort_id)
stored_cohort = @cohort_storage.cohort(cohort_id)
updated_cohort = @cohort_download_api.get_cohort(cohort_id, stored_cohort)
@cohort_storage.put_cohort(updated_cohort)
@cohort_storage.put_cohort(updated_cohort) unless updated_cohort.nil?
end

def remove_job(cohort_id)
Expand Down
4 changes: 0 additions & 4 deletions lib/experiment/error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ def initialize(cohort_id, message)
end
end

# CohortNotModifiedError
class CohortNotModifiedError < CohortDownloadError
end

# CohortTooLargeError
class CohortTooLargeError < CohortDownloadError
end
Expand Down
5 changes: 3 additions & 2 deletions spec/experiment/cohort/cohort_download_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,15 @@ def response(code, body = nil)
expect { api.get_cohort(cohort_id, cohort) }.to raise_error(CohortTooLargeError)
end

it 'raises CohortNotModifiedError for cohort not modified' do
it 'return nil for cohort not modified' do
last_modified = 1000
cohort = Cohort.new(cohort_id, last_modified, 1, [])

stub_request(:get, "#{server_url}/sdk/v1/cohort/#{cohort_id}?lastModified=#{last_modified}&maxCohortSize=#{max_cohort_size}")
.with(headers: headers).to_return(response(204))

expect { api.get_cohort(cohort_id, cohort) }.to raise_error(CohortNotModifiedError)
result = api.get_cohort(cohort_id, cohort)
expect(result).to eq(nil)
end
end
end
Expand Down

0 comments on commit b8ad1ab

Please sign in to comment.