2019-01-15 12:32:14 +00:00
|
|
|
class SearchIndexJob < ApplicationJob
|
2019-11-13 07:03:47 +00:00
|
|
|
include HasActiveJobLock
|
2019-01-15 12:32:14 +00:00
|
|
|
|
2019-05-23 12:03:42 +00:00
|
|
|
retry_on StandardError, attempts: 20, wait: lambda { |executions|
|
|
|
|
executions * 10.seconds
|
|
|
|
}
|
2019-01-15 12:32:14 +00:00
|
|
|
|
2019-11-13 07:03:47 +00:00
|
|
|
def lock_key
|
|
|
|
# "SearchIndexJob/User/42"
|
|
|
|
"#{self.class.name}/#{arguments[0]}/#{arguments[1]}"
|
|
|
|
end
|
|
|
|
|
2019-01-15 12:32:14 +00:00
|
|
|
def perform(object, o_id)
|
2017-01-31 17:13:45 +00:00
|
|
|
@object = object
|
|
|
|
@o_id = o_id
|
|
|
|
|
|
|
|
record = @object.constantize.lookup(id: @o_id)
|
|
|
|
return if !exists?(record)
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2017-01-31 17:13:45 +00:00
|
|
|
record.search_index_update_backend
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def exists?(record)
|
|
|
|
return true if record
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2017-01-31 17:13:45 +00:00
|
|
|
Rails.logger.info "Can't index #{@object}.lookup(id: #{@o_id}), no such record found"
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|