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
|
2020-02-18 14:49:52 +00:00
|
|
|
# "SearchIndexJob/User/42/true"
|
|
|
|
"#{self.class.name}/#{arguments[0]}/#{arguments[1]}/#{arguments[2]}"
|
2019-11-13 07:03:47 +00:00
|
|
|
end
|
|
|
|
|
2020-02-18 14:49:52 +00:00
|
|
|
def perform(object, o_id, update_associations = true)
|
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
|
2020-02-18 14:49:52 +00:00
|
|
|
|
|
|
|
return if !update_associations
|
|
|
|
|
|
|
|
record.search_index_update_associations_delta
|
|
|
|
record.search_index_update_associations_full
|
2017-01-31 17:13:45 +00:00
|
|
|
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
|