Module: Wukong::Store::CassandraModel::ClassMethods
- Defined in:
- lib/wukong/store/cassandra_model.rb,
lib/wukong/store/cassandra/streaming.rb
Instance Method Summary collapse
-
#from_db_hash(*args) ⇒ Object
Override to control how your class is instantiated from the DB hash.
-
#handle_error(action, e) ⇒ Object
invalidates cassandra connection on errors where that makes sense.
-
#insert(key, *args) ⇒ Object
Insert into the cassandra database uses object’s #to_db_hash method.
-
#load(key) ⇒ Object
Insert into the cassandra database calls out to object’s #from_db_hash method.
-
#streaming_insert(id, hsh) ⇒ Object
Use avro and stream into cassandra.
- #streaming_writer ⇒ Object
-
#table_name ⇒ Object
Cassandra column family – taken from the class name by default.
Instance Method Details
#from_db_hash(*args) ⇒ Object
Override to control how your class is instantiated from the DB hash
41 42 43 |
# File 'lib/wukong/store/cassandra_model.rb', line 41 def from_db_hash *args from_hash *args end |
#handle_error(action, e) ⇒ Object
invalidates cassandra connection on errors where that makes sense.
60 61 62 63 64 |
# File 'lib/wukong/store/cassandra_model.rb', line 60 def handle_error action, e warn "#{action} failed: #{e} #{e.backtrace.join("\t")}" ; @cassandra_db = nil sleep 0.2 end |
#insert(key, *args) ⇒ Object
Insert into the cassandra database uses object’s #to_db_hash method
47 48 49 50 |
# File 'lib/wukong/store/cassandra_model.rb', line 47 def insert key, *args hsh = args.first cassandra_db.insert(table_name, key.to_s, hsh) end |
#load(key) ⇒ Object
Insert into the cassandra database calls out to object’s #from_db_hash method
54 55 56 57 |
# File 'lib/wukong/store/cassandra_model.rb', line 54 def load key hsh = cassandra_db.get(self.class_basename, key.to_s) from_db_hash(hsh) if hsh end |
#streaming_insert(id, hsh) ⇒ Object
Use avro and stream into cassandra
21 22 23 |
# File 'lib/wukong/store/cassandra/streaming.rb', line 21 def streaming_insert id, hsh streaming_writer.put(id.to_s, hsh.to_db_hash) end |
#streaming_writer ⇒ Object
14 15 16 |
# File 'lib/wukong/store/cassandra/streaming.rb', line 14 def streaming_writer @streaming_writer ||= AvroWriter.new end |
#table_name ⇒ Object
Cassandra column family – taken from the class name by default.
36 37 38 |
# File 'lib/wukong/store/cassandra_model.rb', line 36 def table_name class_basename end |