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)
if args[:force] || !OnceoffLog.where(job_name: job_name).exists?
execute_onceoff(args)
OnceoffLog.create(job_name: job_name)
DistributedMutex.synchronize(self.class.name) do
execute_onceoff(args)
OnceoffLog.create(job_name: job_name)
end
end
end
def self.enqueue_all
previously_ran = OnceoffLog.pluck(:job_name).uniq
ObjectSpace.each_object(Class).select { |klass| klass < self }.each do |klass|
job_name = name_for(klass).underscore.to_sym
Jobs.enqueue(job_name)
job_name = name_for(klass)
unless previously_ran.include?(job_name)
Jobs.enqueue(job_name.underscore.to_sym)
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
SeedFu.seed
Jobs::Onceoff.enqueue_all
SiteSetting.last_vacuum = Time.now.to_i if SiteSetting.last_vacuum == 0
if SiteSetting.vacuum_db_days > 0 &&