add indexing jobs

This commit is contained in:
Liam P. White 2019-02-19 00:46:26 -05:00
parent 0a50f5f4ea
commit 396d07a5d1
4 changed files with 32 additions and 11 deletions

View File

@ -1,5 +1,5 @@
unicorn: bin/rails server -p 9000 unicorn: bin/rails server -p 9000
jobs: bin/rake jobs:work jobs: bundle exec sidekiq -c 1 -q low_prio -q tags -q default -q high_prio
recommender: bundle exec ruby script/mock_services/recommender.rb recommender: bundle exec ruby script/mock_services/recommender.rb
iqdbs: bundle exec ruby script/mock_services/iqdbs.rb iqdbs: bundle exec ruby script/mock_services/iqdbs.rb
reportbooru: bundle exec ruby script/mock_services/reportbooru.rb reportbooru: bundle exec ruby script/mock_services/reportbooru.rb

View File

@ -24,16 +24,16 @@ module Indexable
end end
def update_index(defer: true, priority: :high) def update_index(defer: true, priority: :high)
# if defer if defer
# if priority == :high if priority == :high
# IndexUpdateJob.perform_later(self.class.to_s, id) IndexUpdateJob.perform_later(self.class.to_s, id)
# elsif priority == :rebuild elsif priority == :rebuild
# IndexRebuildJob.perform_later(self.class.to_s, id) IndexRebuildJob.perform_later(self.class.to_s, id)
# else else
# raise ArgumentError, 'No such priority known' raise ArgumentError, 'No such priority known'
# end end
# else else
__elasticsearch__.index_document __elasticsearch__.index_document
# end end
end end
end end

View File

@ -0,0 +1,11 @@
# frozen_string_literal: true
class IndexRebuildJob < ApplicationJob
queue_as :low_prio
def perform(klass, id)
obj = klass.constantize.find_by(id)
obj.update_index(defer: false) if obj
end
end

View File

@ -0,0 +1,10 @@
# frozen_string_literal: true
class IndexUpdateJob < ApplicationJob
queue_as :high_prio
def perform(klass, id)
obj = klass.constantize.find_by(id)
obj.update_index(defer: false) if obj
end
end