diff options
Diffstat (limited to 'lib/gitlab/database/reindexing/coordinator.rb')
-rw-r--r-- | lib/gitlab/database/reindexing/coordinator.rb | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/lib/gitlab/database/reindexing/coordinator.rb b/lib/gitlab/database/reindexing/coordinator.rb index 0957f43e166..7a7d17ca196 100644 --- a/lib/gitlab/database/reindexing/coordinator.rb +++ b/lib/gitlab/database/reindexing/coordinator.rb @@ -12,26 +12,44 @@ module Gitlab # statement timeouts). TIMEOUT_PER_ACTION = 1.day - attr_reader :indexes + attr_reader :index, :notifier - def initialize(indexes) - @indexes = indexes + def initialize(index, notifier = GrafanaNotifier.new) + @index = index + @notifier = notifier end def perform - indexes.each do |index| - # This obtains a global lease such that there's - # only one live reindexing process at a time. - try_obtain_lease do - ReindexAction.keep_track_of(index) do - ConcurrentReindex.new(index).perform - end + # This obtains a global lease such that there's + # only one live reindexing process at a time. + try_obtain_lease do + action = ReindexAction.create_for(index) + + with_notifications(action) do + perform_for(index, action) end end end private + def with_notifications(action) + notifier.notify_start(action) + yield + ensure + notifier.notify_end(action) + end + + def perform_for(index, action) + ConcurrentReindex.new(index).perform + rescue + action.state = :failed + + raise + ensure + action.finish + end + def lease_timeout TIMEOUT_PER_ACTION end |