Added debug logs for need_sync

This commit is contained in:
M1ha 2019-01-24 11:02:44 +05:00
parent c2a1ecc688
commit 2d2ec9c055
2 changed files with 13 additions and 3 deletions

View File

@ -6,6 +6,7 @@ from collections import defaultdict
from itertools import chain from itertools import chain
from typing import List, Tuple, Iterable, Set, Any, Dict from typing import List, Tuple, Iterable, Set, Any, Dict
import logging
import pytz import pytz
from django.db.models import Model as DjangoModel, QuerySet as DjangoQuerySet from django.db.models import Model as DjangoModel, QuerySet as DjangoQuerySet
from infi.clickhouse_orm.database import Database from infi.clickhouse_orm.database import Database
@ -23,6 +24,9 @@ from .serializers import Django2ClickHouseModelSerializer
from .utils import lazy_class_import, exec_multi_arg_func from .utils import lazy_class_import, exec_multi_arg_func
logger = logging.getLogger('django-clickhouse')
class ClickHouseModelMeta(InfiModelBase): class ClickHouseModelMeta(InfiModelBase):
def __new__(cls, *args, **kwargs): def __new__(cls, *args, **kwargs):
res = super().__new__(cls, *args, **kwargs) # type: ClickHouseModel res = super().__new__(cls, *args, **kwargs) # type: ClickHouseModel
@ -269,14 +273,22 @@ class ClickHouseModel(with_metaclass(ClickHouseModelMeta, InfiModel)):
:return: Boolean :return: Boolean
""" """
if not cls.sync_enabled: if not cls.sync_enabled:
logger.debug('django-clickhouse: need_sync returned False for class %s as sync is deisabled' % cls.__name__)
return False return False
last_sync_time = cls.get_storage().get_last_sync_time(cls.get_import_key()) last_sync_time = cls.get_storage().get_last_sync_time(cls.get_import_key())
if last_sync_time is None: if last_sync_time is None:
logger.debug('django-clickhouse: need_sync returned True for class %s as no last sync found' % cls.__name__)
return True return True
return (datetime.datetime.now() - last_sync_time).total_seconds() >= cls.get_sync_delay() res = (datetime.datetime.now() - last_sync_time).total_seconds() >= cls.get_sync_delay()
logger.debug('django-clickhouse: need_sync returned %s for class %s as no last sync found'
' (now: %s, last: %s, delay: %d)'
% (res, cls.__name__, datetime.datetime.now().isoformat(), last_sync_time.isoformat(),
cls.get_sync_delay()))
return res
class ClickHouseMultiModel(ClickHouseModel): class ClickHouseMultiModel(ClickHouseModel):

View File

@ -39,8 +39,6 @@ def clickhouse_auto_sync():
# Start # Start
for cls in get_subclasses(ClickHouseModel, recursive=True): for cls in get_subclasses(ClickHouseModel, recursive=True):
if cls.need_sync(): if cls.need_sync():
import datetime
print(cls.__name__, datetime.datetime.now().isoformat())
# Даже если синхронизация вдруг не выполнится, не страшно, что мы установили период синхронизации # Даже если синхронизация вдруг не выполнится, не страшно, что мы установили период синхронизации
# Она выполнится следующей таской через интервал. # Она выполнится следующей таской через интервал.
sync_clickhouse_model.delay(cls) sync_clickhouse_model.delay(cls)