Class: Flydata::Parser::Mysql::FlydataMysqlClient

Inherits:
Mysql2::Client
  • Object
show all
Defined in:
lib/flydata/parser/mysql/dump_parser.rb

Overview

Custom mysql client that sets config params (eg:-read_timeout) uniformly for all mysql access. Also, gives access to the last query that was executed using the client which can be helpful when handling exceptions

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(db_opts) ⇒ FlydataMysqlClient

Returns a new instance of FlydataMysqlClient.



233
234
235
236
# File 'lib/flydata/parser/mysql/dump_parser.rb', line 233

def initialize(db_opts)
  #TODO : Pass timeout in as a setting from the data entry
  super(db_opts.merge(read_timeout: 3600))
end

Instance Attribute Details

#last_queryObject

Returns the value of attribute last_query.



231
232
233
# File 'lib/flydata/parser/mysql/dump_parser.rb', line 231

def last_query
  @last_query
end

Instance Method Details

#query(sql, options = {}) ⇒ Object



238
239
240
241
242
243
244
245
246
247
248
# File 'lib/flydata/parser/mysql/dump_parser.rb', line 238

def query(sql, options = {})
  @last_query = sql
  begin
    super(sql, options)
  rescue Mysql2::Error => e
    if  /^Timeout waiting for a response/ === e.to_s
      raise "The below query timed out when running. Please check long running processes and locks in your database.\n#{last_query}"
    end
    raise e
  end
end