From 822b67ca105498957847669f2656a70b08e0a6cb Mon Sep 17 00:00:00 2001 From: Christophe Bliard Date: Tue, 3 Sep 2024 16:33:48 +0200 Subject: [PATCH 1/2] Bump mustermann gem --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index ca1bf896aaf9..f3c89a818753 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -755,7 +755,7 @@ GEM minitest (5.25.1) msgpack (1.7.2) multi_json (1.15.0) - mustermann (3.0.2) + mustermann (3.0.3) ruby2_keywords (~> 0.0.1) mustermann-grape (1.1.0) mustermann (>= 1.0.0) From b192b97117cbec4de8a35838305312178c3a0160 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20G=C3=BCnther?= Date: Tue, 3 Sep 2024 17:14:14 +0200 Subject: [PATCH 2/2] RakeJob: Load the rake task if it wasn't found --- app/workers/rake_job.rb | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/app/workers/rake_job.rb b/app/workers/rake_job.rb index ef2414614305..1c7525ae98bd 100644 --- a/app/workers/rake_job.rb +++ b/app/workers/rake_job.rb @@ -28,7 +28,7 @@ require "rake" ## -# Invoke a rake task while safely loading the tasks only once +# Invoke a rake task while loading the tasks on demand # to ensure they are only loaded once. module RakeJob attr_reader :task_name, :args @@ -44,29 +44,26 @@ def perform(task_name, *args) protected def invoke - load_tasks! - task.invoke *args - ensure - task&.reenable + if (task = load_task) + task.reenable + task.invoke *args + else + OpenProject.logger.error { "Rake task #{task_name} not found for background job." } + end end ## - # Load tasks if there are none. This should only be run once in an environment - def load_tasks! - Rails.application.load_rake_tasks unless tasks_loaded? - end + # Load tasks if we don't find our task + def load_task + Rails.application.load_rake_tasks unless task_loaded? - ## - # Reference to the task name. - # Will raise NameError or NoMethodError depending on what of rake is (not) loaded - def task - Rake::Task[task_name] + task_loaded? && Rake::Task[task_name] end ## # Returns whether any task is loaded # Will raise NameError or NoMethodError depending on what of rake is (not) loaded - def tasks_loaded? - !Rake::Task.tasks.empty? + def task_loaded? + Rake::Task.task_defined?(task_name) end end