From d98e9fc0d91532fc5035a5d395acff2f9e169137 Mon Sep 17 00:00:00 2001 From: Richard Lynch Date: Tue, 12 Nov 2024 16:04:03 +0000 Subject: [PATCH] Ensure tasks are loaded If the task isn't loaded this method errors with Don't know how to build task 'dfe:analytics:import_entity' This change ensures the rake tasks are loaded --- lib/analytics_importer.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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