log.rb 1.08 KB
Newer Older
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

def log_contains(message, logtype = 'SystemGo', log_timeout = 30)
  client = connect_to_db(@server_database)
  rows_affected = 0
  Timeout::timeout(log_timeout) {
      loop do
        debug_msg "Waiting for log to contain \"#{message}\"."
        result = client.execute("SELECT * FROM [#{@server_database}].[dbo].[Log] \
                                WHERE logtype LIKE '#{logtype}' AND message LIKE '#{message}'")
        rows_affected = result.do
        break if rows_affected > 0
        sleep 1
      end
  }
  rows_affected > 0
end

def log_contains_immediate(message, logtype = 'SystemGo')
  client = connect_to_db(@server_database)
  debug_msg "Checking log for \"#{message}\"."
  result = client.execute("SELECT * FROM [#{@server_database}].[dbo].[Log] \
                          WHERE logtype LIKE '#{logtype}' AND message LIKE '#{message}'")
  rows_affected = result.do
  rows_affected > 0
end
26 27 28 29 30 31 32

def clear_log()
  client = connect_to_db(@server_database)
  result = client.execute("DELETE
    FROM [#{@server_database}].[dbo].[Log]")
  debug_msg "Rows deleted from [Log]: #{result.do}"
end