Skip to content
This repository has been archived by the owner on May 31, 2024. It is now read-only.

Commit

Permalink
Merge pull request #25 from itkq/add-wait-timeout-option
Browse files Browse the repository at this point in the history
Add --wait-timeout option
  • Loading branch information
winebarrel committed Apr 22, 2019
2 parents e72beed + 8b13107 commit dcce642
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 27 deletions.
55 changes: 28 additions & 27 deletions bin/gratan
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -35,33 +35,34 @@ options = {


ARGV.options do |opt| ARGV.options do |opt|
begin begin
opt.on('' , '--host HOST') {|v| mysql_options[:host] = v } opt.on('' , '--host HOST') {|v| mysql_options[:host] = v }
opt.on('' , '--port PORT', Integer) {|v| mysql_options[:port] = v } opt.on('' , '--port PORT', Integer) {|v| mysql_options[:port] = v }
opt.on('' , '--socket SOCKET') {|v| mysql_options[:socket] = v } opt.on('' , '--socket SOCKET') {|v| mysql_options[:socket] = v }
opt.on('' , '--username USERNAME') {|v| mysql_options[:username] = v } opt.on('' , '--username USERNAME') {|v| mysql_options[:username] = v }
opt.on('' , '--password PASSWORD') {|v| mysql_options[:password] = v } opt.on('' , '--password PASSWORD') {|v| mysql_options[:password] = v }
opt.on('' , '--database DATABASE') {|v| mysql_options[:database] = v } opt.on('' , '--database DATABASE') {|v| mysql_options[:database] = v }
opt.on('-a', '--apply') { mode = :apply } opt.on('-a', '--apply') { mode = :apply }
opt.on('-f', '--file FILE') {|v| file = v } opt.on('-f', '--file FILE') {|v| file = v }
opt.on('' , '--dry-run') { options[:dry_run] = true } opt.on('' , '--dry-run') { options[:dry_run] = true }
opt.on('-e', '--export') { mode = :export } opt.on('-e', '--export') { mode = :export }
opt.on('' , '--with-identifier') { options[:with_identifier] = true } opt.on('' , '--with-identifier') { options[:with_identifier] = true }
opt.on('' , '--split') { split = true } opt.on('' , '--split') { split = true }
opt.on('' , '--chunk-by-user') { options[:chunk_by_user] = true } opt.on('' , '--chunk-by-user') { options[:chunk_by_user] = true }
opt.on('-o', '--output FILE') {|v| output_file = v } opt.on('-o', '--output FILE') {|v| output_file = v }
opt.on('' , '--ignore-user REGEXP') {|v| options[:ignore_user] = Regexp.new(v) } opt.on('' , '--ignore-user REGEXP') {|v| options[:ignore_user] = Regexp.new(v) }
opt.on('' , '--target-user REGEXP') {|v| options[:target_user] = Regexp.new(v) } opt.on('' , '--target-user REGEXP') {|v| options[:target_user] = Regexp.new(v) }
opt.on('' , '--ignore-object REGEXP') {|v| options[:ignore_object] = Regexp.new(v) } opt.on('' , '--ignore-object REGEXP') {|v| options[:ignore_object] = Regexp.new(v) }
opt.on('' , '--enable-expired') { options[:enable_expired] = true } opt.on('' , '--enable-expired') { options[:enable_expired] = true }
opt.on('' , '--ignore-not-exist') {|v| options[:ignore_not_exist] = true } opt.on('' , '--ignore-not-exist') {|v| options[:ignore_not_exist] = true }
opt.on('' , '--ignore-password-secret') {|v| options[:ignore_password_secret] = true } opt.on('' , '--ignore-password-secret') {|v| options[:ignore_password_secret] = true }
opt.on('' , '--skip-disable-log-bin') { options[:skip_disable_log_bin] = true } opt.on('' , '--skip-disable-log-bin') { options[:skip_disable_log_bin] = true }
opt.on('' , '--override-sql-mode') { options[:override_sql_mode] = true } opt.on('' , '--override-sql-mode') { options[:override_sql_mode] = true }
opt.on('' , '--use-show-create-user') { options[:use_show_create_user] = true } opt.on('' , '--use-show-create-user') { options[:use_show_create_user] = true }
opt.on('' , '--no-color') { options[:color] = false } opt.on('' , '--no-color') { options[:color] = false }
opt.on('' , '--debug') { options[:debug] = true } opt.on('' , '--debug') { options[:debug] = true }
opt.on('' , '--auto-identify OUTPUT') {|v| options[:identifier] = Gratan::Identifier::Auto.new(v, options) } opt.on('' , '--wait-timeout SECOND', Integer) {|v| options[:wait_timeout] = v }
opt.on('' , '--csv-identify CSV') {|v| options[:identifier] = Gratan::Identifier::CSV.new(v, options) } opt.on('' , '--auto-identify OUTPUT') {|v| options[:identifier] = Gratan::Identifier::Auto.new(v, options) }
opt.on('' , '--csv-identify CSV') {|v| options[:identifier] = Gratan::Identifier::CSV.new(v, options) }


opt.on('' , '--mysql2-options JSON') do |json| opt.on('' , '--mysql2-options JSON') do |json|
json = JSON.parse(json) json = JSON.parse(json)
Expand Down
1 change: 1 addition & 0 deletions lib/gratan/client.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ def in_progress
begin begin
@driver.disable_log_bin_local @driver.disable_log_bin_local
@driver.override_sql_mode @driver.override_sql_mode
@driver.set_wait_timeout
@updated = false @updated = false
yield yield
updated = @updated updated = @updated
Expand Down
6 changes: 6 additions & 0 deletions lib/gratan/driver.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -215,6 +215,12 @@ def override_sql_mode
end end
end end


def set_wait_timeout
if @options[:wait_timeout]
query("SET @@wait_timeout = #{@options[:wait_timeout]}")
end
end

private private


def query(sql) def query(sql)
Expand Down

0 comments on commit dcce642

Please sign in to comment.