Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/release/14.5' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverguenther committed Sep 3, 2024
2 parents 5052150 + b192b97 commit 4e3cced
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,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)
Expand Down
29 changes: 13 additions & 16 deletions app/workers/rake_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit 4e3cced

Please sign in to comment.