Module: Wukong::Store::CassandraModel::ClassMethods
- Defined in:
- lib/wukong/store/cassandra_model.rb,
lib/wukong/store/cassandra/streaming.rb
Instance Method Summary (collapse)
-
- (Object) from_db_hash(*args)
Override to control how your class is instantiated from the DB hash.
-
- (Object) handle_error(action, e)
invalidates cassandra connection on errors where that makes sense.
-
- (Object) insert(key, *args)
Insert into the cassandra database uses object's #to_db_hash method.
-
- (Object) load(key)
Insert into the cassandra database calls out to object's #from_db_hash method.
-
- (Object) streaming_insert(id, hsh)
Use avro and stream into cassandra.
- - (Object) streaming_writer
-
- (Object) table_name
Cassandra column family -- taken from the class name by default.
Instance Method Details
- (Object) from_db_hash(*args)
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 |
- (Object) handle_error(action, e)
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 |
- (Object) insert(key, *args)
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 |
- (Object) load(key)
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 |
- (Object) streaming_insert(id, hsh)
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 |
- (Object) streaming_writer
14 15 16 |
# File 'lib/wukong/store/cassandra/streaming.rb', line 14 def streaming_writer @streaming_writer ||= AvroWriter.new end |
- (Object) table_name
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 |