Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Remove RakeJob to stop reliance on Rake tasks loading

Oliver Günther1b65464e216a
diff --git a/app/workers/cron/clear_old_sessions_job.rb b/app/workers/cron/clear_old_sessions_job.rb
index 08857446348..6384af94aae 100644
--- a/app/workers/cron/clear_old_sessions_job.rb
+++ b/app/workers/cron/clear_old_sessions_job.rb
@@ -28,8 +28,6 @@
module Cron
class ClearOldSessionsJob < ApplicationJob
- include ::RakeJob
-
def perform
Sessions::ClearOldSessionsService.call!
end
diff --git a/app/workers/cron/clear_tmp_cache_job.rb b/app/workers/cron/clear_tmp_cache_job.rb
index b07a08c748f..1661d2cd686 100644
--- a/app/workers/cron/clear_tmp_cache_job.rb
+++ b/app/workers/cron/clear_tmp_cache_job.rb
@@ -28,10 +28,10 @@
module Cron
class ClearTmpCacheJob < ApplicationJob
- include ::RakeJob
-
+ ##
+ # Clear the tmp/cache directory in case a file caching is configured
def perform
- super("tmp:cache:clear")
+ FileUtils.rm_rf(Dir["tmp/cache/[^.]*"], verbose: false)
end
end
end
diff --git a/app/workers/cron/clear_uploaded_files_job.rb b/app/workers/cron/clear_uploaded_files_job.rb
index aa959c4b0c9..ee0fa6d6636 100644
--- a/app/workers/cron/clear_uploaded_files_job.rb
+++ b/app/workers/cron/clear_uploaded_files_job.rb
@@ -28,10 +28,8 @@
module Cron
class ClearUploadedFilesJob < ApplicationJob
- include ::RakeJob
-
def perform
- super("attachments:clear")
+ Attachment.clean_cached_files!
end
end
end
diff --git a/app/workers/oauth/cleanup_job.rb b/app/workers/oauth/cleanup_job.rb
index 67ada7b3280..1045fae94c1 100644
--- a/app/workers/oauth/cleanup_job.rb
+++ b/app/workers/oauth/cleanup_job.rb
@@ -28,12 +28,11 @@
module OAuth
class CleanupJob < ApplicationJob
- include ::RakeJob
-
queue_with_priority :low
def perform
- super("doorkeeper:db:cleanup")
+ cleaner = Doorkeeper::StaleRecordsCleaner.new(Doorkeeper.config.access_token_model)
+ cleaner.clean_revoked
end
end
end
diff --git a/app/workers/rake_job.rb b/app/workers/rake_job.rb
deleted file mode 100644
index 1b414fa1431..00000000000
--- a/app/workers/rake_job.rb
+++ /dev/null
@@ -1,69 +0,0 @@
-#-- copyright
-# OpenProject is an open source project management software.
-# Copyright (C) the OpenProject GmbH
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License version 3.
-#
-# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
-# Copyright (C) 2006-2013 Jean-Philippe Lang
-# Copyright (C) 2010-2013 the ChiliProject Team
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# See COPYRIGHT and LICENSE files for more details.
-#++
-require "rake"
-
-##
-# Invoke a rake task while loading the tasks on demand
-# to ensure they are only loaded once.
-module RakeJob
- attr_reader :task_name, :args
-
- def perform(task_name, *args)
- @task_name = task_name
- @args = args
-
- Rails.logger.info { "Invoking Rake task #{task_name}." }
- invoke
- end
-
- protected
-
- def invoke
- 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 we don't find our task
- def load_task
- Rails.application.load_tasks unless task_loaded?
-
- 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 task_loaded?
- Rake::Task.task_defined?(task_name)
- end
-end