summaryrefslogtreecommitdiff
path: root/lib/gitlab/database/async_indexes/index_creator.rb
blob: c5f4c5f30add35db6f2cf6637c1b4e0002573e6c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# frozen_string_literal: true

module Gitlab
  module Database
    module AsyncIndexes
      class IndexCreator < AsyncIndexes::IndexBase
        STATEMENT_TIMEOUT = 20.hours

        private

        override :preconditions_met?
        def preconditions_met?
          !index_exists?
        end

        override :action_type
        def action_type
          'creation'
        end

        override :around_execution
        def around_execution(&block)
          set_statement_timeout(&block)
        end

        def set_statement_timeout
          connection.execute("SET statement_timeout TO '%ds'" % STATEMENT_TIMEOUT)
          yield
        ensure
          connection.execute('RESET statement_timeout')
        end
      end
    end
  end
end