Skip to content

Commit

Permalink
Revert "Merge pull request opf#12998 from opf/task/48717-replace-dela…
Browse files Browse the repository at this point in the history
…yedjob"
  • Loading branch information
Eric-Guo committed Mar 27, 2024
1 parent ecf4877 commit 6d23eb5
Show file tree
Hide file tree
Showing 94 changed files with 1,241 additions and 1,137 deletions.
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ gem "multi_json", "~> 1.15.0"
gem "oj", "~> 3.16.0"

gem "daemons"
gem "good_job", "= 3.26.2" # update should be done manually in sync with saas-openproject version.
gem "delayed_cron_job", "~> 0.9.0"
gem "delayed_job_active_record", "~> 4.1.5"

gem "rack-protection", "~> 3.2.0"

Expand Down
57 changes: 39 additions & 18 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -496,8 +496,10 @@ GEM
descendants_tracker (~> 0.0.1)
color_conversion (0.1.1)
colored2 (4.0.0)
commonmarker (1.0.4)
rb_sys (~> 0.9)
commonmarker (1.0.4-aarch64-linux)
commonmarker (1.0.4-arm64-darwin)
commonmarker (1.0.4-x86_64-darwin)
commonmarker (1.0.4-x86_64-linux)
compare-xml (0.66)
nokogiri (~> 1.8)
concurrent-ruby (1.2.3)
Expand Down Expand Up @@ -531,6 +533,13 @@ GEM
deckar01-task_list (2.3.4)
html-pipeline (~> 2.0)
declarative (0.0.20)
delayed_cron_job (0.9.0)
fugit (>= 1.5)
delayed_job (4.1.11)
activesupport (>= 3.0, < 8.0)
delayed_job_active_record (4.1.8)
activerecord (>= 3.0, < 8.0)
delayed_job (>= 3.0, < 5)
descendants_tracker (0.0.4)
thread_safe (~> 0.3, >= 0.3.1)
diff-lcs (1.5.1)
Expand Down Expand Up @@ -648,13 +657,6 @@ GEM
i18n (>= 0.7)
multi_json
request_store (>= 1.0)
good_job (3.26.2)
activejob (>= 6.0.0)
activerecord (>= 6.0.0)
concurrent-ruby (>= 1.0.2)
fugit (>= 1.1)
railties (>= 6.0.0)
thor (>= 0.14.1)
google-apis-core (0.14.1)
addressable (~> 2.5, >= 2.5.1)
googleauth (~> 1.9)
Expand All @@ -667,7 +669,10 @@ GEM
google-apis-core (>= 0.14.0, < 2.a)
google-cloud-env (2.1.1)
faraday (>= 1.0, < 3.a)
google-protobuf (3.25.3)
google-protobuf (3.25.3-aarch64-linux)
google-protobuf (3.25.3-arm64-darwin)
google-protobuf (3.25.3-x86_64-darwin)
google-protobuf (3.25.3-x86_64-linux)
googleapis-common-protos-types (1.14.0)
google-protobuf (~> 3.18)
googleauth (1.11.0)
Expand All @@ -688,7 +693,16 @@ GEM
grape
rack
gravatar_image_tag (1.2.0)
grpc (1.62.0)
grpc (1.62.0-aarch64-linux)
google-protobuf (~> 3.25)
googleapis-common-protos-types (~> 1.0)
grpc (1.62.0-arm64-darwin)
google-protobuf (~> 3.25)
googleapis-common-protos-types (~> 1.0)
grpc (1.62.0-x86_64-darwin)
google-protobuf (~> 3.25)
googleapis-common-protos-types (~> 1.0)
grpc (1.62.0-x86_64-linux)
google-protobuf (~> 3.25)
googleapis-common-protos-types (~> 1.0)
grpc-tools (1.62.0)
Expand Down Expand Up @@ -829,7 +843,6 @@ GEM
mime-types-data (3.2024.0305)
mini_magick (4.12.0)
mini_mime (1.1.5)
mini_portile2 (2.8.5)
minitest (5.22.3)
msgpack (1.7.2)
multi_json (1.15.0)
Expand Down Expand Up @@ -857,8 +870,13 @@ GEM
net-protocol
net-ssh (7.2.1)
nio4r (2.7.0)
nokogiri (1.16.3)
mini_portile2 (~> 2.8.2)
nokogiri (1.16.3-aarch64-linux)
racc (~> 1.4)
nokogiri (1.16.3-arm64-darwin)
racc (~> 1.4)
nokogiri (1.16.3-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.16.3-x86_64-linux)
racc (~> 1.4)
oj (3.16.3)
bigdecimal (>= 3.0)
Expand Down Expand Up @@ -1028,7 +1046,6 @@ GEM
rb-fsevent (0.11.2)
rb-inotify (0.10.1)
ffi (~> 1.0)
rb_sys (0.9.90)
rbtree3 (0.7.1)
rdoc (6.6.3.1)
psych (>= 4.0.0)
Expand Down Expand Up @@ -1158,7 +1175,7 @@ GEM
unf (~> 0.1.4)
slop (4.10.1)
smart_properties (1.17.0)
sorbet-runtime (0.5.11295)
sorbet-runtime (0.5.11301)
spreadsheet (1.3.1)
bigdecimal
ruby-ole
Expand Down Expand Up @@ -1279,7 +1296,10 @@ GEM
zeitwerk (2.6.13)

PLATFORMS
ruby
aarch64-linux
arm64-darwin
x86_64-darwin
x86_64-linux

DEPENDENCIES
actionpack-xml_parser (~> 2.0.0)
Expand Down Expand Up @@ -1331,6 +1351,8 @@ DEPENDENCIES
debug
debugbar
deckar01-task_list (~> 2.3.1)
delayed_cron_job (~> 0.9.0)
delayed_job_active_record (~> 4.1.5)
disposable (~> 0.6.2)
doorkeeper (~> 5.6.6)
dotenv-rails
Expand All @@ -1349,7 +1371,6 @@ DEPENDENCIES
friendly_id (~> 5.5.0)
fuubar (~> 2.5.0)
gon (~> 6.4.0)
good_job (= 3.26.2)
google-apis-gmail_v1
googleauth
grape (~> 2.0.0)
Expand Down
2 changes: 1 addition & 1 deletion Procfile.dev
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
web: bundle exec rails server -p 3000 -b ${HOST:="127.0.0.1"} --environment ${RAILS_ENV:="development"}
angular: yarn run serve
worker: bundle exec good_job start
worker: bundle exec rake jobs:work
4 changes: 1 addition & 3 deletions app/contracts/settings/working_days_params_contract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ def working_days_are_present
end

def unique_job
if GoodJob::Job
.where(finished_at: nil)
.exists?(job_class: WorkPackages::ApplyWorkingDaysChangeJob.name)
if WorkPackages::ApplyWorkingDaysChangeJob.scheduled?
errors.add :base, :previous_working_day_changes_unprocessed
end
end
Expand Down
6 changes: 3 additions & 3 deletions app/seeders/root_seeder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,13 @@ def prepare_seed!
ActionMailer::Base.perform_deliveries = false

# Avoid asynchronous DeliverWorkPackageCreatedJob
previous_execution_mode = Rails.configuration.good_job.execution_mode
Rails.configuration.good_job.execution_mode = :inline
previous_delay_jobs = Delayed::Worker.delay_jobs
Delayed::Worker.delay_jobs = false

yield
ensure
ActionMailer::Base.perform_deliveries = previous_perform_deliveries
Rails.configuration.good_job.execution_mode = previous_execution_mode
Delayed::Worker.delay_jobs = previous_delay_jobs
end

def seed_basic_data
Expand Down
4 changes: 0 additions & 4 deletions app/workers/application_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,6 @@ def reload_mailer_settings!
Setting.reload_mailer_settings!
end

def job_scheduled_at
GoodJob::Job.where(id: job_id).pick(:scheduled_at)
end

private

def prepare_job_context
Expand Down
7 changes: 5 additions & 2 deletions app/workers/attachments/cleanup_uncontainered_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@
# See COPYRIGHT and LICENSE files for more details.
#++

class Attachments::CleanupUncontaineredJob < ApplicationJob
class Attachments::CleanupUncontaineredJob < Cron::CronJob
queue_with_priority :low

# runs at 10:03 pm
self.cron_expression = "03 22 * * *"

def perform
Attachment
.where(container: nil)
Expand All @@ -47,7 +50,7 @@ def too_old
attachment_table = Attachment.arel_table

attachment_table[:created_at]
.lteq(Time.zone.now - OpenProject::Configuration.attachments_grace_period.minutes)
.lteq(Time.now - OpenProject::Configuration.attachments_grace_period.minutes)
.to_sql
end
end
41 changes: 41 additions & 0 deletions app/workers/concerns/scheduled_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# OpenProject is an open source project management software.
# Copyright (C) 2010-2022 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.

module ScheduledJob
extend ActiveSupport::Concern

class_methods do
##
# Is there a job scheduled?
def scheduled?
delayed_job_query.exists?
end

def delayed_job_query
Delayed::Job.where("handler LIKE ?", "%job_class: #{name}%")
end
end
end
5 changes: 4 additions & 1 deletion app/workers/cron/clear_old_sessions_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@
#++

module Cron
class ClearOldSessionsJob < ApplicationJob
class ClearOldSessionsJob < CronJob
include ::RakeJob

# runs at 1:15 nightly
self.cron_expression = "15 1 * * *"

def perform
super("db:sessions:expire", 7)
end
Expand Down
5 changes: 4 additions & 1 deletion app/workers/cron/clear_tmp_cache_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@
#++

module Cron
class ClearTmpCacheJob < ApplicationJob
class ClearTmpCacheJob < CronJob
include ::RakeJob

# runs at 02:45 sundays
self.cron_expression = "45 2 * * 7"

def perform
super("tmp:cache:clear")
end
Expand Down
5 changes: 4 additions & 1 deletion app/workers/cron/clear_uploaded_files_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@
#++

module Cron
class ClearUploadedFilesJob < ApplicationJob
class ClearUploadedFilesJob < CronJob
include ::RakeJob

# Runs 23pm fridays
self.cron_expression = "0 23 * * 5"

def perform
super("attachments:clear")
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,55 +23,53 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See docs/COPYRIGHT.rdoc for more details.
# See COPYRIGHT and LICENSE files for more details.
#++
module OpenProject
module HealthChecks
class PumaCheck < OkComputer::Check
attr_reader :threshold

def initialize(threshold = OpenProject::Configuration.health_checks_backlog_threshold)
@threshold = threshold.to_i
@applicable = Object.const_defined?("Puma::Server") && !Puma::Server.current.nil?
super()
end
module Cron
class CronJob < ApplicationJob
class_attribute :cron_expression

# List of registered jobs, requires eager load in dev(!)
class_attribute :registered_jobs, default: []

def check
stats = self.stats
include ScheduledJob

return mark_message "N/A as Puma is not used." if stats.nil?
class << self
##
# Register new job class(es)
def register!(*job_classes)
Array(job_classes).each do |clz|
raise ArgumentError, "Needs to be subclass of ::Cron::CronJob" unless clz.ancestors.include?(self)

if stats[:running] > 0
mark_message "Puma is running"
else
mark_failure
mark_message "Puma is not running"
registered_jobs << clz
end
end

if stats[:backlog] < threshold
mark_message "Backlog ok"
else
mark_failure
mark_message "Backlog congested"
def schedule_registered_jobs!
registered_jobs.each do |job_class|
job_class.ensure_scheduled!
end
end

def stats
return nil unless applicable?
##
# Ensure the job is scheduled unless it is already
def ensure_scheduled!
# Ensure scheduled only once
return if scheduled?

server = Puma::Server.current
return nil if server.nil?
Rails.logger.info { "Scheduling #{name} recurrent background job." }
set(cron: cron_expression).perform_later
end

{
backlog: server.backlog || 0,
running: server.running || 0,
pool_capacity: server.pool_capacity || 0,
max_threads: server.max_threads || 0
}
##
# Remove the scheduled job, if any
def remove
delayed_job&.destroy
end

def applicable?
!!@applicable
def delayed_job
delayed_job_query.first
end
end
end
Expand Down
Loading

0 comments on commit 6d23eb5

Please sign in to comment.