Merge remote-tracking branch 'origin/release/11.4' into release/12.0

pull/9836/head
Oliver Günther 3 years ago
commit a9b051a92b
No known key found for this signature in database
GPG Key ID: A3A8BDAD7C0C552C
  1. 18
      app/workers/cron/cron_job.rb
  2. 2
      lib/tasks/cron.rake

@ -46,10 +46,16 @@ module Cron
end
end
def schedule_registered_jobs!
registered_jobs.each do |job_class|
job_class.ensure_scheduled!
end
end
##
# Ensure the job is scheduled unless it is already
def ensure_scheduled!
# Ensure scheduled only onced
# Ensure scheduled only once
return if scheduled?
Rails.logger.info { "Scheduling #{name} recurrent background job." }
@ -65,13 +71,15 @@ module Cron
##
# Is there a job scheduled?
def scheduled?
delayed_job.present?
delayed_job_query.exists?
end
def delayed_job
Delayed::Job
.where('handler LIKE ?', "%job_class: #{name}%")
.first
delayed_job_query.first
end
def delayed_job_query
Delayed::Job.where('handler LIKE ?', "%job_class: #{name}%")
end
end
end

@ -34,6 +34,6 @@ namespace 'openproject:cron' do
desc 'Ensure the cron-like background jobs are actively scheduled'
task schedule: [:environment] do
::Cron::CronJob.registered_jobs.each(&:ensure_scheduled!)
::Cron::CronJob.schedule_registered_jobs!
end
end

Loading…
Cancel
Save