Added method to flush single import_key in storage

This commit is contained in:
M1ha 2019-07-15 17:43:36 +05:00
parent 85a785eb59
commit 842f43b242
2 changed files with 12 additions and 0 deletions

View File

@ -58,6 +58,8 @@ class ClickHouseModel(with_metaclass(ClickHouseModelMeta, InfiModel)):
sync_storage = None
sync_delay = None
sync_lock_timeout = None
# This flag gives ability to disable to_db_string while inserting data, if it is already formatted
sync_formatted_tuples = False
# This attribute is initialized in metaclass, as it must get model class as a parameter

View File

@ -280,6 +280,16 @@ class RedisStorage(with_metaclass(SingletonMeta, Storage)):
key = "%s.sync.%s.queue" % (config.STATSD_PREFIX, model.get_import_key())
statsd.gauge(key, 0)
def flush_import_key(self, import_key):
keys = [
self.REDIS_KEY_RANK_TEMPLATE.format(import_key=import_key),
self.REDIS_KEY_OPS_TEMPLATE.format(import_key=import_key),
self.REDIS_KEY_LOCK.format(import_key=import_key),
self.REDIS_KEY_LAST_SYNC_TS.format(import_key=import_key)
]
self._redis.delete(*keys)
statsd.gauge("%s.sync.%s.queue" % (config.STATSD_PREFIX, import_key), 0)
def get_last_sync_time(self, import_key):
sync_ts_key = self.REDIS_KEY_LAST_SYNC_TS.format(import_key=import_key)
res = self._redis.get(sync_ts_key)