Class: LogwormTail
- Inherits:
-
Object
- Object
- LogwormTail
- Defined in:
- lib/logworm_utils/tail.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(table, options) ⇒ LogwormTail
constructor
A new instance of LogwormTail.
- #run ⇒ Object
Constructor Details
#initialize(table, options) ⇒ LogwormTail
Returns a new instance of LogwormTail.
2 3 4 5 6 7 8 9 10 11 12 13 |
# File 'lib/logworm_utils/tail.rb', line 2 def initialize(table, ) @table = table = begin @db = Logworm::DB.from_config_or_die([:app]) @query = Logworm::QueryBuilder.new(.merge(:force_ts => true)) rescue Exception => e $stderr.puts "Error: #{e}" exit(-1) end end |
Class Method Details
.list(options = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/logworm_utils/tail.rb', line 15 def self.list( = {}) begin @db = Logworm::DB.from_config_or_die([:app]) @tables = @db.tables if @tables and @tables.size > 0 puts "The following are the tables that you've created thus far:" @tables.sort {|x,y| x["tablename"] <=> y["tablename"]}.each do |t| puts "\t - #{t["tablename"]}, #{t["rows"]} rows, last updated on #{date_time(t["last_write"])}" end else puts "You haven't recorded any data yet." end rescue Exception => e $stderr.puts "Error: #{e}" exit(-1) end end |
Instance Method Details
#run ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/logworm_utils/tail.rb', line 33 def run # Create a resource for the query begin query_data = @db.query(@table, @query.to_json) url = query_data["results_uri"] rescue Logworm::DatabaseException, Logworm::ForbiddenAccessException => e $stderr.puts "Error: #{e}" exit(-1) rescue Logworm::InvalidQueryException => e $stderr.puts "#{e}" exit(-1) rescue Exception => e $stderr.puts "Error: #{e}" exit(-1) end if [:debug] puts "logworm query: #{@query.to_json}" puts "logworm query url: #{query_data["self_uri"]}" puts "logworm results url: #{url}" puts "refresh frequency: #{@options[:frequency]}" if [:loop] puts end while true do begin last_printed = print_rows(@db.results(url + "?nocache=1")["results"], last_printed || nil) rescue Logworm::DatabaseException, Logworm::ForbiddenAccessException => e $stderr.puts "Error: #{e}" exit(-1) rescue Logworm::InvalidQueryException => e $stderr.puts "#{e}" exit(-1) rescue Exception => e $stderr.puts "Error: #{e}" exit(-1) end exit(0) unless [:loop] sleep [:frequency] end end |