Class: MoSQL::Tailer
- Inherits:
-
Mongoriver::AbstractPersistentTailer
- Object
- Mongoriver::AbstractPersistentTailer
- MoSQL::Tailer
- Defined in:
- lib/mosql/tailer.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(backends, type, table, opts) ⇒ Tailer
constructor
A new instance of Tailer.
- #read_timestamp ⇒ Object
- #write_timestamp(ts) ⇒ Object
Constructor Details
#initialize(backends, type, table, opts) ⇒ Tailer
Returns a new instance of Tailer.
12 13 14 15 16 |
# File 'lib/mosql/tailer.rb', line 12 def initialize(backends, type, table, opts) super(backends, type, opts) @table = table @service = opts[:service] || "mosql" end |
Class Method Details
.create_table(db, tablename) ⇒ Object
3 4 5 6 7 8 9 10 |
# File 'lib/mosql/tailer.rb', line 3 def self.create_table(db, tablename) db.create_table?(tablename) do column :service, 'TEXT' column :timestamp, 'INTEGER' primary_key [:service] end db[tablename.to_sym] end |
Instance Method Details
#read_timestamp ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/mosql/tailer.rb', line 18 def row = @table.where(:service => @service).select([:timestamp]).first if row BSON::Timestamp.new(row[:timestamp], 0) else BSON::Timestamp.new(0, 0) end end |
#write_timestamp(ts) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/mosql/tailer.rb', line 27 def (ts) begin @table.insert({:service => @service, :timestamp => ts.seconds}) rescue Sequel::DatabaseError => e raise unless e. =~ /duplicate key value violates unique constraint/ @table.where(:service => @service).update(:timestamp => ts.seconds) end end |