Skip to content

Instantly share code, notes, and snippets.

@julesce
Last active August 29, 2015 13:56
Show Gist options
  • Select an option

  • Save julesce/8971779 to your computer and use it in GitHub Desktop.

Select an option

Save julesce/8971779 to your computer and use it in GitHub Desktop.
#
# There are a couple of drips that have not had their RLinkIndex created, since they are returning false for archived_mailing_links?
# This script attempts to fix this, by ensuring that the index is created, and archived_mailing_links? returns true
#
require 'logger'
Object.const_set(:RIAK_DISABLE_SECONDARY_INDEXES, false)
logger = Logger.new('log/fix_drip_clicks.log')
logger.info "====================== S T A R T ========================"
Drip.find_each do |drip|
should_refresh_stats = false
logger.info "Working on drip #{drip.id}"
if drip.promotion.present?
drip.promotion.dedicated_mailings.each do |m|
link_keys = RMailingLink.find_all_keys_by_index(:mailing_id, m.id)
if link_keys.empty?
m.mailing_archive.update_attribute(:mailing_links, false)
else
index = RLinkIndex.find(m.id)
if index.blank?
should_refresh_stats = true
logger.info "RLinkIndex does not exist for mailing #{m.id}"
# Archive mailing links to riak
m.archive_mailing_links!
# Build the index
RLinkIndex.create(m.id, link_keys)
logger.info "RLinkIndex created for mailing #{m.id}"
end
end
end
if should_refresh_stats
logger.info "Refreshing stats..."
drip.promotion.refresh_stats
end
else
logger.info "Promotion does not exist."
end
logger.info "----------------------------------"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment