Skip to content

Commit

Permalink
refactor 'cron' job scheduling
Browse files Browse the repository at this point in the history
  • Loading branch information
fwolfst committed Oct 12, 2020
1 parent 3aeb043 commit db1916b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
6 changes: 3 additions & 3 deletions app/lib/scheduled_job_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# SPDX-License-Identifier: AGPL-3.0-or-later

class ScheduledJobCheck

def self.all_cron_job_classes
glob = Rails.root.join('app', 'jobs', '**', '*_job.rb')
Dir.glob(glob).each {|f| require f}
Expand All @@ -14,7 +13,8 @@ def self.all_scheduled?
all_cron_job_classes.all? { |job| job.scheduled? }
end

def self.schedule_all
all_cron_job_classes.each { |job| job.scheduled }
def self.schedule_all!
Rails.logger.info 'Scheduling all cronish jobs'
all_cron_job_classes.each { |job| job.schedule }
end
end
4 changes: 1 addition & 3 deletions lib/tasks/jobs.rake
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
namespace :db do
desc 'Schedule all cron jobs'
task schedule_jobs: :environment do
glob = Rails.root.join('app', 'jobs', '**', '*_job.rb')
Dir.glob(glob).each {|f| require f}
CronJob.subclasses.each { |job| job.schedule }
ScheduledJobCheck.schedule_all!
end
end

Expand Down

0 comments on commit db1916b

Please sign in to comment.