Try running once off jobs outside of db:migrate

This commit is contained in:
Robin Ward 2016-04-07 15:07:24 -04:00
parent 078b3bc87e
commit 3f7ced9236
3 changed files with 21 additions and 6 deletions

View file

@ -10,15 +10,21 @@ class Jobs::Onceoff < Jobs::Base
job_name = self.class.name_for(self.class) job_name = self.class.name_for(self.class)
if args[:force] || !OnceoffLog.where(job_name: job_name).exists? if args[:force] || !OnceoffLog.where(job_name: job_name).exists?
execute_onceoff(args) DistributedMutex.synchronize(self.class.name) do
OnceoffLog.create(job_name: job_name) execute_onceoff(args)
OnceoffLog.create(job_name: job_name)
end
end end
end end
def self.enqueue_all def self.enqueue_all
previously_ran = OnceoffLog.pluck(:job_name).uniq
ObjectSpace.each_object(Class).select { |klass| klass < self }.each do |klass| ObjectSpace.each_object(Class).select { |klass| klass < self }.each do |klass|
job_name = name_for(klass).underscore.to_sym job_name = name_for(klass)
Jobs.enqueue(job_name) unless previously_ran.include?(job_name)
Jobs.enqueue(job_name.underscore.to_sym)
end
end end
end end

View file

@ -0,0 +1,11 @@
module Jobs
class EnqueueOnceoffs < Jobs::Scheduled
every 10.minutes
def execute(args)
Jobs::Onceoff.enqueue_all
end
end
end

View file

@ -7,8 +7,6 @@ end
task 'db:migrate' => ['environment', 'set_locale'] do task 'db:migrate' => ['environment', 'set_locale'] do
SeedFu.seed SeedFu.seed
Jobs::Onceoff.enqueue_all
SiteSetting.last_vacuum = Time.now.to_i if SiteSetting.last_vacuum == 0 SiteSetting.last_vacuum = Time.now.to_i if SiteSetting.last_vacuum == 0
if SiteSetting.vacuum_db_days > 0 && if SiteSetting.vacuum_db_days > 0 &&