Sha256: 1cd6ce63d9627339be235ffb49a22444db7e81efa71fee40167ff2149efd292e
Contents?: true
Size: 1.04 KB
Versions: 3
Compression:
Stored size: 1.04 KB
Contents
module MoSQL class Tailer < Mongoriver::AbstractPersistentTailer 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 def initialize(backends, type, table, opts) super(backends, type, opts) @table = table @service = opts[:service] || "mosql" end def read_timestamp row = @table.where(:service => @service).select([:timestamp]).first if row BSON::Timestamp.new(row[:timestamp], 0) else BSON::Timestamp.new(0, 0) end end def write_timestamp(ts) unless @did_insert begin @table.insert({:service => @service, :timestamp => ts.seconds}) rescue Sequel::DatabaseError => e raise unless MoSQL::SQLAdapter.duplicate_key_error?(e) end @did_insert = true end @table.where(:service => @service).update(:timestamp => ts.seconds) end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
mosql-0.3.2 | lib/mosql/tailer.rb |
mosql-0.3.1 | lib/mosql/tailer.rb |
mosql-0.3.0 | lib/mosql/tailer.rb |