Skip to content
Browse files

Catch rummager errors for artefact slug migrator

  • Loading branch information...
1 parent 8478117 commit 479648473d515645f306ec73ccf8b5be8d03784d @JordanHatch JordanHatch committed Oct 8, 2012
Showing with 17 additions and 9 deletions.
  1. +1 −1 data/slugs_to_migrate.json
  2. +16 −8 lib/artefact_slug_migrator.rb
View
2 data/slugs_to_migrate.json
@@ -113,7 +113,7 @@
"apply-help-school-clothing-costs": "help-school-clothing-costs",
"your-rights-as-a-trade-union-rep": "rights-of-trade-union-reps",
"monitored-at-work-your-rights": "monitoring-work-workers-rights",
- "/business-transfers-and-takeovers-your-rights": "business-transfers-takeovers-workers-rights",
+ "business-transfers-and-takeovers-your-rights": "business-transfers-takeovers-workers-rights",
"employment-tribunal": "taking-employer-to-employment-tribunal",
"report-debris-litter-motorways-main-roads": "report-debris-motorways-main-roads"
}
View
24 lib/artefact_slug_migrator.rb
@@ -8,16 +8,24 @@ def initialize(logger = nil)
def run
logger.info "Migrating slugs for #{slugs.size} artefacts"
+ Artefact.observers.disable :update_search_observer
+
slugs.each do |slug, new_slug|
artefact = Artefact.where(slug: slug).first
- raise "Artefact not found with slug #{slug}" if artefact.nil?
-
- rummageable_artefact = RummageableArtefact.new(artefact)
- rummageable_artefact.delete
-
- artefact.update_attribute(:slug, new_slug)
-
- logger.info " #{slug} -> #{new_slug}"
+ if artefact
+ artefact.update_attribute(:slug, new_slug)
+
+ begin
+ rummageable_artefact = RummageableArtefact.new(artefact)
+ rummageable_artefact.delete
+ rescue e
+ logger.error "Could not remove artefact from search -> #{e}"
+ end
+
+ logger.info " #{slug} -> #{new_slug}"
+ else
+ logger.error "Artefact not found with slug #{slug}"
+ end
end
logger.info "Sequence complete."
end

0 comments on commit 4796484

Please sign in to comment.
Something went wrong with that request. Please try again.