mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 15:48:43 -05:00
Log once off jobs and enqueue on db:migrate
This commit is contained in:
parent
855f72deb6
commit
078b3bc87e
5 changed files with 43 additions and 6 deletions
25
app/jobs/onceoff.rb
Normal file
25
app/jobs/onceoff.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
class Jobs::Onceoff < Jobs::Base
|
||||
sidekiq_options retry: false
|
||||
|
||||
def self.name_for(klass)
|
||||
klass.name.sub(/^Jobs\:\:/, '')
|
||||
end
|
||||
|
||||
# Pass `force: true` to force it happen again
|
||||
def execute(args)
|
||||
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)
|
||||
end
|
||||
end
|
||||
|
||||
def self.enqueue_all
|
||||
ObjectSpace.each_object(Class).select { |klass| klass < self }.each do |klass|
|
||||
job_name = name_for(klass).underscore.to_sym
|
||||
Jobs.enqueue(job_name)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -1,10 +1,8 @@
|
|||
module Jobs
|
||||
|
||||
class GrantEmoji < Jobs::Base
|
||||
sidekiq_options retry: false
|
||||
|
||||
def execute(args)
|
||||
class GrantEmoji < Jobs::Onceoff
|
||||
|
||||
def execute_onceoff(args)
|
||||
to_award = {}
|
||||
|
||||
Post.secured(Guardian.new).visible.public_posts.find_in_batches(batch_size: 5000) do |group|
|
||||
|
|
2
app/models/onceoff_log.rb
Normal file
2
app/models/onceoff_log.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
class OnceoffLog < ActiveRecord::Base
|
||||
end
|
10
db/migrate/20160407180149_create_onceoff_logs.rb
Normal file
10
db/migrate/20160407180149_create_onceoff_logs.rb
Normal file
|
@ -0,0 +1,10 @@
|
|||
class CreateOnceoffLogs < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :onceoff_logs do |t|
|
||||
t.string :job_name
|
||||
t.timestamps null: false
|
||||
end
|
||||
|
||||
add_index :onceoff_logs, :job_name
|
||||
end
|
||||
end
|
|
@ -7,6 +7,8 @@ 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 &&
|
||||
|
@ -82,7 +84,7 @@ task 'db:rebuild_indexes' => 'environment' do
|
|||
begin
|
||||
puts index_name
|
||||
User.exec_sql("DROP INDEX public.#{index_name}")
|
||||
rescue ActiveRecord::StatementInvalid => e
|
||||
rescue ActiveRecord::StatementInvalid
|
||||
# It's this:
|
||||
# PG::Error: ERROR: cannot drop index category_users_pkey because constraint category_users_pkey on table category_users requires it
|
||||
# HINT: You can drop constraint category_users_pkey on table category_users instead.
|
||||
|
@ -94,7 +96,7 @@ task 'db:rebuild_indexes' => 'environment' do
|
|||
index_definitions[table_name].each do |index_def|
|
||||
begin
|
||||
User.exec_sql(index_def)
|
||||
rescue ActiveRecord::StatementInvalid => e
|
||||
rescue ActiveRecord::StatementInvalid
|
||||
# Trying to recreate a primary key
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue