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
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
iqdbs: bundle exec ruby script/mock_services/iqdbs.rb
reportbooru: bundle exec ruby script/mock_services/reportbooru.rb

View File

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