From 842f43b24255675521b34a157313dd824165798c Mon Sep 17 00:00:00 2001 From: M1ha Date: Mon, 15 Jul 2019 17:43:36 +0500 Subject: [PATCH] Added method to flush single import_key in storage --- src/django_clickhouse/clickhouse_models.py | 2 ++ src/django_clickhouse/storages.py | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/src/django_clickhouse/clickhouse_models.py b/src/django_clickhouse/clickhouse_models.py index 1bb28e7..1b34c8d 100644 --- a/src/django_clickhouse/clickhouse_models.py +++ b/src/django_clickhouse/clickhouse_models.py @@ -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 diff --git a/src/django_clickhouse/storages.py b/src/django_clickhouse/storages.py index e16a5ac..84720a4 100644 --- a/src/django_clickhouse/storages.py +++ b/src/django_clickhouse/storages.py @@ -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)