diff --git a/lib/analytics_importer.rb b/lib/analytics_importer.rb index 0e6d8274d4..e29a4a767c 100644 --- a/lib/analytics_importer.rb +++ b/lib/analytics_importer.rb @@ -1,5 +1,13 @@ class AnalyticsImporter + ANALYTICS_SYNC_TASK = "dfe:analytics:import_entity" + def self.import(model) - Rake::Task["dfe:analytics:import_entity"].invoke(model.table_name) if DfE::Analytics.enabled? + return unless DfE::Analytics.enabled? + + if Rake::Task.tasks.map(&:name).exclude?(ANALYTICS_SYNC_TASK) + Rails.application.load_tasks + end + + Rake::Task[ANALYTICS_SYNC_TASK].invoke(model.table_name) end end