Skip to content

Commit

Permalink
Fix issues
Browse files Browse the repository at this point in the history
  • Loading branch information
vallbull committed Nov 9, 2023
1 parent 6aa51f2 commit 38bc2bc
Show file tree
Hide file tree
Showing 17 changed files with 66 additions and 47 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
from dl_constants.enums import NotificationType

from dl_connector_clickhouse.core.clickhouse_base.constants import BACKEND_TYPE_CLICKHOUSE


BACKEND_TYPE_CHS3 = BACKEND_TYPE_CLICKHOUSE

NOTIF_TYPE_STALE_DATA = NotificationType.declare("stale_data")
NOTIF_TYPE_DATA_UPDATE_FAILURE = NotificationType.declare("data_update_failure")
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from typing import Optional

from dl_constants.enums import NotificationLevel
from dl_core.reporting.notifications import BaseNotification

from constants import NOTIF_TYPE_STALE_DATA, NOTIF_TYPE_DATA_UPDATE_FAILURE


class StaleDataNotification(BaseNotification):
type = NOTIF_TYPE_STALE_DATA
_title = "Stale data"
_message = "The data has not been updated for more than 30 minutes, a background update is in progress"
_level = NotificationLevel.info


class DataUpdateFailureNotification(BaseNotification):
def __init__(self, err_code: str, request_id: Optional[str]) -> None:
super().__init__()
self.err_code = err_code
self.request_id = request_id or "unknown"

type = NOTIF_TYPE_DATA_UPDATE_FAILURE
_title = "Data update failed"
_message = (
"The displayed data may be outdated due to the failure of the last update.\n"
"Reason: {err_code}, Request-ID: {request_id}."
)
_level = NotificationLevel.warning

@property
def message(self) -> str:
return self._message.format(err_code=self.err_code, request_id=self.request_id)
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
from dl_constants.enums import (
ConnectionType,
DataSourceType,
NotificationType,
)

from dl_connector_bundle_chs3.constants import (
NOTIF_TYPE_DATA_UPDATE_FAILURE,
NOTIF_TYPE_STALE_DATA,
)


CONNECTION_TYPE_GSHEETS_V2 = ConnectionType.declare("gsheets_v2")
SOURCE_TYPE_GSHEETS_V2 = DataSourceType.declare("GSHEETS_V2")

NOTIF_TYPE_GSHEETS_V2_STALE_DATA = NOTIF_TYPE_STALE_DATA
NOTIF_TYPE_GSHEETS_V2_DATA_UPDATE_FAILURE = NOTIF_TYPE_DATA_UPDATE_FAILURE
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
from dl_core import exc
from dl_core.reporting.notifications import get_notification_record

from dl_connector_bundle_chs3.chs3_base.core.constants import NOTIF_TYPE_DATA_UPDATE_FAILURE
from dl_connector_bundle_chs3.chs3_base.core.data_source import BaseFileS3DataSource
from dl_connector_bundle_chs3.chs3_gsheets.core.constants import (
CONNECTION_TYPE_GSHEETS_V2,
NOTIF_TYPE_GSHEETS_V2_DATA_UPDATE_FAILURE,
SOURCE_TYPE_GSHEETS_V2,
)

Expand Down Expand Up @@ -44,7 +44,7 @@ class ThisDataSourceError(exc.DataSourceErrorFromComponentError):
# may be generalized in the future
reporting_registry.save_reporting_record(
get_notification_record(
NOTIF_TYPE_GSHEETS_V2_DATA_UPDATE_FAILURE,
NOTIF_TYPE_DATA_UPDATE_FAILURE,
err_code=".".join(single_error.code),
request_id=single_error.details.get("request-id"),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
make_user_auth_headers,
)

from dl_connector_bundle_chs3.chs3_base.core.constants import NOTIF_TYPE_STALE_DATA
from dl_connector_bundle_chs3.chs3_base.core.lifecycle import BaseFileS3ConnectionLifecycleManager
from dl_connector_bundle_chs3.chs3_gsheets.core.constants import NOTIF_TYPE_GSHEETS_V2_STALE_DATA
from dl_connector_bundle_chs3.chs3_gsheets.core.us_connection import GSheetsFileS3Connection


Expand Down Expand Up @@ -40,7 +40,7 @@ async def post_exec_async_hook(self) -> None:
and (dt_now - data_updated_at_all).total_seconds() >= self.STALE_THRESHOLD_SECONDS
):
reporting_registry = self._service_registry.get_reporting_registry()
reporting_registry.save_reporting_record(get_notification_record(NOTIF_TYPE_GSHEETS_V2_STALE_DATA))
reporting_registry.save_reporting_record(get_notification_record(NOTIF_TYPE_STALE_DATA))

data_updated_at = data.oldest_data_update_time(exclude_statuses={FileProcessingStatus.in_progress})
if data_updated_at is None or (dt_now - data_updated_at).total_seconds() < self.STALE_THRESHOLD_SECONDS:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
from dl_constants.enums import NotificationLevel
from dl_core.reporting.notifications import BaseNotification

from dl_connector_bundle_chs3.chs3_gsheets.core.constants import (
NOTIF_TYPE_GSHEETS_V2_DATA_UPDATE_FAILURE,
NOTIF_TYPE_GSHEETS_V2_STALE_DATA,
from dl_connector_bundle_chs3.chs3_base.core.constants import (
NOTIF_TYPE_DATA_UPDATE_FAILURE,
NOTIF_TYPE_STALE_DATA,
)


class StaleDataNotification(BaseNotification):
type = NOTIF_TYPE_GSHEETS_V2_STALE_DATA
type = NOTIF_TYPE_STALE_DATA
_title = "Stale data"
_message = "The data has not been updated for more than 30 minutes, a background update is in progress"
_level = NotificationLevel.info
Expand All @@ -22,7 +22,7 @@ def __init__(self, err_code: str, request_id: Optional[str]) -> None:
self.err_code = err_code
self.request_id = request_id or "unknown"

type = NOTIF_TYPE_GSHEETS_V2_DATA_UPDATE_FAILURE
type = NOTIF_TYPE_DATA_UPDATE_FAILURE
_title = "Data update failed"
_message = (
"The displayed data may be outdated due to the failure of the last update.\n"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
from dl_constants.enums import (
ConnectionType,
DataSourceType,
NotificationType,
)
from dl_connector_bundle_chs3.constants import NOTIF_TYPE_STALE_DATA, NOTIF_TYPE_DATA_UPDATE_FAILURE

CONNECTION_TYPE_YADOCS = ConnectionType.declare("yadocs")
SOURCE_TYPE_YADOCS = DataSourceType.declare("YADOCS")

NOTIF_TYPE_YADOCS_STALE_DATA = NOTIF_TYPE_STALE_DATA
NOTIF_TYPE_YADOCS_DATA_UPDATE_FAILURE = NOTIF_TYPE_DATA_UPDATE_FAILURE
CONNECTION_TYPE_YADOCS = ConnectionType.declare("docs")
SOURCE_TYPE_YADOCS = DataSourceType.declare("YADOCS")
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
from dl_core import exc
from dl_core.reporting.notifications import get_notification_record

from dl_connector_bundle_chs3.chs3_base.core.constants import NOTIF_TYPE_DATA_UPDATE_FAILURE
from dl_connector_bundle_chs3.chs3_base.core.data_source import BaseFileS3DataSource
from dl_connector_bundle_chs3.chs3_yadocs.core.constants import (
CONNECTION_TYPE_YADOCS,
NOTIF_TYPE_YADOCS_DATA_UPDATE_FAILURE,
SOURCE_TYPE_YADOCS,
)

Expand Down Expand Up @@ -44,7 +44,7 @@ class ThisDataSourceError(exc.DataSourceErrorFromComponentError):
# may be generalized in the future
reporting_registry.save_reporting_record(
get_notification_record(
NOTIF_TYPE_YADOCS_DATA_UPDATE_FAILURE,
NOTIF_TYPE_DATA_UPDATE_FAILURE,
err_code=".".join(single_error.code),
request_id=single_error.details.get("request-id"),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
make_user_auth_headers,
)

from dl_connector_bundle_chs3.chs3_base.core.constants import NOTIF_TYPE_STALE_DATA
from dl_connector_bundle_chs3.chs3_base.core.lifecycle import BaseFileS3ConnectionLifecycleManager
from dl_connector_bundle_chs3.chs3_yadocs.core.constants import NOTIF_TYPE_YADOCS_STALE_DATA
from dl_connector_bundle_chs3.chs3_yadocs.core.us_connection import YaDocsFileS3Connection


Expand Down Expand Up @@ -40,7 +40,7 @@ async def post_exec_async_hook(self) -> None:
and (dt_now - data_updated_at_all).total_seconds() >= self.STALE_THRESHOLD_SECONDS
):
reporting_registry = self._service_registry.get_reporting_registry()
reporting_registry.save_reporting_record(get_notification_record(NOTIF_TYPE_YADOCS_STALE_DATA))
reporting_registry.save_reporting_record(get_notification_record(NOTIF_TYPE_STALE_DATA))

data_updated_at = data.oldest_data_update_time(exclude_statuses={FileProcessingStatus.in_progress})
if data_updated_at is None or (dt_now - data_updated_at).total_seconds() < self.STALE_THRESHOLD_SECONDS:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
from dl_constants.enums import NotificationLevel
from dl_core.reporting.notifications import BaseNotification

from dl_connector_bundle_chs3.chs3_yadocs.core.constants import (
NOTIF_TYPE_YADOCS_DATA_UPDATE_FAILURE,
NOTIF_TYPE_YADOCS_STALE_DATA,
from dl_connector_bundle_chs3.chs3_base.core.constants import (
NOTIF_TYPE_DATA_UPDATE_FAILURE,
NOTIF_TYPE_STALE_DATA,
)


class StaleDataNotification(BaseNotification):
type = NOTIF_TYPE_YADOCS_STALE_DATA
type = NOTIF_TYPE_STALE_DATA
_title = "Stale data"
_message = "The data has not been updated for more than 30 minutes, a background update is in progress"
_level = NotificationLevel.info
Expand All @@ -22,7 +22,7 @@ def __init__(self, err_code: str, request_id: Optional[str]) -> None:
self.err_code = err_code
self.request_id = request_id or "unknown"

type = NOTIF_TYPE_YADOCS_DATA_UPDATE_FAILURE
type = NOTIF_TYPE_DATA_UPDATE_FAILURE
_title = "Data update failed"
_message = (
"The displayed data may be outdated due to the failure of the last update.\n"
Expand Down

This file was deleted.

Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: [email protected]\n"
"POT-Creation-Date: 2023-09-22 08:14+0000\n"
"POT-Creation-Date: 2023-11-09 14:12+0000\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

msgid "label_connector-gsheets_v2"
msgstr "Google Sheets"

msgid "label_connector-gsheets_v2"
msgid "label_connector-yadocs"
msgstr "Yandex Documents"

msgid "label_connector-file"
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: [email protected]\n"
"POT-Creation-Date: 2023-09-22 08:14+0000\n"
"POT-Creation-Date: 2023-11-09 14:12+0000\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from dl_core.us_manager.us_manager_sync import SyncUSManager
from dl_testing.regulated_test import RegulatedTestParams

from dl_connector_bundle_chs3.chs3_gsheets.core.constants import NOTIF_TYPE_GSHEETS_V2_STALE_DATA
from dl_connector_bundle_chs3.chs3_base.core.constants import NOTIF_TYPE_STALE_DATA
from dl_connector_bundle_chs3.chs3_gsheets.core.lifecycle import GSheetsFileS3ConnectionLifecycleManager
from dl_connector_bundle_chs3.chs3_gsheets.core.us_connection import GSheetsFileS3Connection
from dl_connector_bundle_chs3_tests.db.base.api.data import CHS3DataResultTestSuite
Expand Down Expand Up @@ -66,7 +66,7 @@ def get_notifications_from_result_resp() -> list[dict]:
# it is not time to update data yet, so we expect no data updates or corresponding notifications
notifications = get_notifications_from_result_resp()
assert all(
notification["locator"] != NOTIF_TYPE_GSHEETS_V2_STALE_DATA.value for notification in notifications
notification["locator"] != NOTIF_TYPE_STALE_DATA.value for notification in notifications
), notifications
conn = sync_us_manager.get_by_id(saved_connection_id, GSheetsFileS3Connection)
assert conn.data.sources[0].data_updated_at == data_updated_at_orig
Expand All @@ -82,7 +82,7 @@ def get_notifications_from_result_resp() -> list[dict]:
# now notifications should be there, as well as connection sources should be updated
notifications = get_notifications_from_result_resp()
assert any(
notification["locator"] == NOTIF_TYPE_GSHEETS_V2_STALE_DATA.value for notification in notifications
notification["locator"] == NOTIF_TYPE_STALE_DATA.value for notification in notifications
), notifications
conn = sync_us_manager.get_by_id(saved_connection_id, GSheetsFileS3Connection)
assert conn.data.sources[0].data_updated_at != data_updated_at
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from dl_core.us_manager.us_manager_sync import SyncUSManager
from dl_testing.regulated_test import RegulatedTestParams

from dl_connector_bundle_chs3.chs3_yadocs.core.constants import NOTIF_TYPE_YADOCS_STALE_DATA
from dl_connector_bundle_chs3.chs3_base.core.constants import NOTIF_TYPE_STALE_DATA
from dl_connector_bundle_chs3.chs3_yadocs.core.lifecycle import YaDocsFileS3ConnectionLifecycleManager
from dl_connector_bundle_chs3.chs3_yadocs.core.us_connection import YaDocsFileS3Connection
from dl_connector_bundle_chs3_tests.db.base.api.data import CHS3DataResultTestSuite
Expand Down Expand Up @@ -66,7 +66,7 @@ def get_notifications_from_result_resp() -> list[dict]:
# it is not time to update data yet, so we expect no data updates or corresponding notifications
notifications = get_notifications_from_result_resp()
assert all(
notification["locator"] != NOTIF_TYPE_YADOCS_STALE_DATA.value for notification in notifications
notification["locator"] != NOTIF_TYPE_STALE_DATA.value for notification in notifications
), notifications
conn = sync_us_manager.get_by_id(saved_connection_id, YaDocsFileS3Connection)
assert conn.data.sources[0].data_updated_at == data_updated_at_orig
Expand All @@ -82,7 +82,7 @@ def get_notifications_from_result_resp() -> list[dict]:
# now notifications should be there, as well as connection sources should be updated
notifications = get_notifications_from_result_resp()
assert any(
notification["locator"] == NOTIF_TYPE_YADOCS_STALE_DATA.value for notification in notifications
notification["locator"] == NOTIF_TYPE_STALE_DATA.value for notification in notifications
), notifications
conn = sync_us_manager.get_by_id(saved_connection_id, YaDocsFileS3Connection)
assert conn.data.sources[0].data_updated_at != data_updated_at
Expand Down

0 comments on commit 38bc2bc

Please sign in to comment.