Class: PgHaMigrations::BlockingDatabaseTransactions::LongRunningTransaction

Inherits:
Struct
  • Object
show all
Defined in:
lib/pg_ha_migrations/blocking_database_transactions.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ LongRunningTransaction

Returns a new instance of LongRunningTransaction.



4
5
6
7
8
# File 'lib/pg_ha_migrations/blocking_database_transactions.rb', line 4

def initialize(*args)
  super

  self.tables_with_locks = tables_with_locks.map { |args| Table.new(*args) }.select(&:present?)
end

Instance Attribute Details

#current_queryObject

Returns the value of attribute current_query

Returns:

  • (Object)

    the current value of current_query



3
4
5
# File 'lib/pg_ha_migrations/blocking_database_transactions.rb', line 3

def current_query
  @current_query
end

#databaseObject

Returns the value of attribute database

Returns:

  • (Object)

    the current value of database



3
4
5
# File 'lib/pg_ha_migrations/blocking_database_transactions.rb', line 3

def database
  @database
end

#stateObject

Returns the value of attribute state

Returns:

  • (Object)

    the current value of state



3
4
5
# File 'lib/pg_ha_migrations/blocking_database_transactions.rb', line 3

def state
  @state
end

#tables_with_locksObject

Returns the value of attribute tables_with_locks

Returns:

  • (Object)

    the current value of tables_with_locks



3
4
5
# File 'lib/pg_ha_migrations/blocking_database_transactions.rb', line 3

def tables_with_locks
  @tables_with_locks
end

#transaction_ageObject

Returns the value of attribute transaction_age

Returns:

  • (Object)

    the current value of transaction_age



3
4
5
# File 'lib/pg_ha_migrations/blocking_database_transactions.rb', line 3

def transaction_age
  @transaction_age
end

Instance Method Details

#concurrent_index_creation?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/pg_ha_migrations/blocking_database_transactions.rb', line 19

def concurrent_index_creation?
  !!current_query.match(/create\s+index\s+concurrently/i)
end

#descriptionObject



10
11
12
13
14
15
16
17
# File 'lib/pg_ha_migrations/blocking_database_transactions.rb', line 10

def description
  [
    database,
    tables_with_locks.size > 0 ? "tables (#{tables_with_locks.map(&:fully_qualified_name).join(', ')})" : nil,
    "#{idle? ? "currently idle " : ""}transaction open for #{transaction_age}",
    "#{idle? ? "last " : ""}query: #{current_query}",
  ].compact.join(" | ")
end

#idle?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/pg_ha_migrations/blocking_database_transactions.rb', line 23

def idle?
  state == "idle in transaction"
end