|
|
|
@ -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 |
|
|
|
|