Module: OpenC3::DbShardedModel
- Included in:
- InterfaceStatusModel, MetricModel, MicroserviceStatusModel
- Defined in:
- lib/openc3/models/db_sharded_model.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#_db_sharded_create(db_shard, update: false, force: false, queued: false, isoformat: false, expire_seconds: nil) ⇒ Object
DB_Shard-aware create: writes to the store instance for the given db_shard.
-
#_db_sharded_destroy(db_shard) ⇒ Object
DB_Shard-aware destroy: deletes from the store instance for the given db_shard.
Class Method Details
.included(base) ⇒ Object
20 21 22 |
# File 'lib/openc3/models/db_sharded_model.rb', line 20 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#_db_sharded_create(db_shard, update: false, force: false, queued: false, isoformat: false, expire_seconds: nil) ⇒ Object
DB_Shard-aware create: writes to the store instance for the given db_shard.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/openc3/models/db_sharded_model.rb', line 82 def _db_sharded_create(db_shard, update: false, force: false, queued: false, isoformat: false, expire_seconds: nil) db_shard_store = self.class.store.instance(db_shard: db_shard) unless force existing = db_shard_store.hget(@primary_key, @name) if existing raise RuntimeError.new("#{@primary_key}:#{@name} already exists at create") unless update else raise RuntimeError.new("#{@primary_key}:#{@name} doesn't exist at update") if update end end @updated_at = isoformat ? Time.now.utc.iso8601 : Time.now.utc.to_nsec_from_epoch if queued store = self.class.store_queued.instance(db_shard: db_shard) store.hset(@primary_key, @name, JSON.generate(self.as_json(), allow_nan: true)) store.call(:hexpire, @primary_key, expire_seconds, 'FIELDS', 1, @name) if expire_seconds else db_shard_store.hset(@primary_key, @name, JSON.generate(self.as_json(), allow_nan: true)) db_shard_store.call(:hexpire, @primary_key, expire_seconds, 'FIELDS', 1, @name) if expire_seconds end end |
#_db_sharded_destroy(db_shard) ⇒ Object
DB_Shard-aware destroy: deletes from the store instance for the given db_shard.
105 106 107 108 |
# File 'lib/openc3/models/db_sharded_model.rb', line 105 def _db_sharded_destroy(db_shard) @destroyed = true self.class.store.instance(db_shard: db_shard).hdel(@primary_key, @name) end |