bin/lhm-kill-queue in lhm-1.0.0.rc6 vs bin/lhm-kill-queue in lhm-1.0.0.rc7
- old
+ new
@@ -1,15 +1,19 @@
#!/usr/bin/env ruby
require 'active_record'
+require 'lhm/sql_helper'
require 'optparse'
module Lhm
class KillQueue
def initialize
@port = 3306
+ @grace = 10
+ @tiny = 0.1
+ @marker = "%#{ SqlHelper.annotation }%"
OptionParser.new do |opts|
opts.on("-h", "--hostname HOSTNAME") { |v| @hostname = v }
opts.on("-u", "--username USERNAME") { |v| @username = v }
opts.on("-p", "--password PASSWORD") { |v| @password = v }
@@ -29,11 +33,11 @@
connect
end
def usage
<<-desc.gsub(/^ /, '')
- kills queries on the given server after detecting 'lock table% -- lhm'.
+ kills queries on the given server after detecting 'lock table#{ @marker }'.
usage:
lhm-kill-queue -h hostname -u username -p password -d database \\
(-m kill | -m master | -m slave) [--confirm]
desc
@@ -52,28 +56,28 @@
kill_process(lock)
end
def master
lock = trip
- puts "starting to kill non lhm processes in 1 second"
- sleep(1.05)
+ puts "starting to kill non lhm processes in #{ @grace } seconds"
+ sleep(@grace + @tiny)
[list_non_lhm].flatten.each do |process|
kill_process(process)
- sleep(0.05)
+ sleep(@tiny)
end
end
def slave
lock = trip
- puts "starting to kill non lhm SELECT processes in 1 second"
- sleep(1)
+ puts "starting to kill non lhm SELECT processes in #{ @grace } seconds"
+ sleep(@grace + @tiny)
[list_non_lhm].flatten.each do |process|
if(select?(process))
kill_process(process)
- sleep(0.05)
+ sleep(@tiny)
end
end
end
private
@@ -92,15 +96,17 @@
def connection
ActiveRecord::Base.connection
end
def list_non_lhm
- select_processes("info not like '% -- lhm' and time > 0 and command = 'Query'")
+ select_processes %Q(
+ info not like '#{ @marker }' and time > #{ @grace } and command = 'Query'
+ )
end
def trip
- until res = select_processes("info like 'lock table% -- lhm'")
- sleep 0.2
+ until res = select_processes("info like 'lock table#{ @marker }'").first
+ sleep @tiny
print '.'
end
res
end