-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from solver-it-sro/fix-reindex-job
GO-205 GO-206 GO-207 Fix reindex job
- Loading branch information
Showing
4 changed files
with
28 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,21 @@ | ||
class Searchable::ReindexMessageThreadJob < ApplicationJob | ||
queue_as :default | ||
|
||
include GoodJob::ActiveJobExtensions::Concurrency | ||
|
||
good_job_control_concurrency_with( | ||
# Maximum number of unfinished jobs to allow with the concurrency key | ||
# Can be an Integer or Lambda/Proc that is invoked in the context of the job | ||
total_limit: 1, | ||
|
||
key: -> { "Searchable::ReindexMessageThreadJob-#{arguments.first.try(:id)}" } | ||
) | ||
|
||
discard_on ActiveJob::DeserializationError | ||
|
||
def perform(message_thread) | ||
return if message_thread.nil? | ||
|
||
::Searchable::MessageThread.index_record(message_thread) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,15 @@ | ||
class ApplicationRecord < ActiveRecord::Base | ||
self.abstract_class = true | ||
|
||
class FailedToAcquireLockError < StandardError | ||
end | ||
|
||
def self.with_advisory_lock!(lock_name, options = {}, &block) | ||
result = with_advisory_lock_result(lock_name, options, &block) | ||
if result.lock_was_acquired? | ||
result.result | ||
else | ||
raise FailedToAcquireLockError | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters