Last active
April 16, 2019 06:54
-
-
Save clarkbab/354a8fe2c4bfb0125fa5074da6c2077b to your computer and use it in GitHub Desktop.
Checks the GPI Domain
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## | |
# Checks a shard for outdated GPlay RISs. | |
# | |
# +shard_id+, the shard to run on. | |
def check_shard(shard_id) | |
domain = 'https://gplaychannel.zendesk.com' | |
external_id = '29004837bb8774aebbc595ffc00618c9f4609de66d5ea775950' | |
keys = %i(manifest_url admin_ui_url pull_url channelback_url clickthrough_url health_check_url) | |
errors = [] | |
ActiveRecord::Base.on_shard(shard_id) do | |
puts "Shard ID: #{shard_id}" | |
Channels::AnyChannel::RegisteredIntegrationService.where(external_id: external_id).each do |ris| | |
keys.each do |key| | |
unless ris.send(key).include?(domain) | |
# Add the RIS and the reason for the error. | |
reason = nil | |
if ::Account.find_by(id: ris.account_id).nil? | |
reason = 'missing_account' | |
else | |
reason = 'unknown' | |
end | |
errors.push([ris, reason]) | |
end | |
end | |
end | |
end | |
return errors | |
end | |
## | |
# Checks a pod for outdated RISs. | |
# | |
# +pod_id+, the pod ID. | |
def check_pod(pod_id) | |
shards = Zendesk::Configuration.dig('pods', pod_id, 'shards') | |
errors = [] | |
shards.each do |shard_id| | |
errors += check_shard(shard_id) | |
end | |
return errors | |
end | |
## | |
# Check ISI state and last_polled_at. | |
# | |
# +errors+, an array of [RIS, 'error_type'] pairs. | |
def check_isis(errors) | |
errors.map do |e| | |
a = ::Account.find(e[0].account_id) | |
ActiveRecord::Base.on_shard(a.shard_id) do | |
e[0].integration_service_instances.map { |isi| [isi.state, isi.last_polled_at] } | |
end | |
end.flatten(1) | |
end | |
## | |
# Returns the deletion dates for those RIS records with soft-deleted accounts. | |
# | |
# +errors+, an array of [RIS, 'error_type'] pairs. | |
def deletion_dates(errors) | |
errors.map do |e| | |
::Account.unscoped.find(e[0].account_id).deleted_at | |
end.flatten(1) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment