Skip to content
This repository has been archived by the owner on Apr 3, 2024. It is now read-only.

Commit

Permalink
chore: fix quality checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian2012 committed Aug 17, 2023
1 parent dd129ba commit eff0fc7
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 14 deletions.
6 changes: 5 additions & 1 deletion event_sink_clickhouse/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,8 @@ def ready(self):
"""
super().ready()

from event_sink_clickhouse import signals, sinks, tasks # pylint: disable=import-outside-toplevel, unused-import
from event_sink_clickhouse import ( # pylint: disable=import-outside-toplevel, unused-import
signals,
sinks,
tasks,
)
17 changes: 14 additions & 3 deletions event_sink_clickhouse/serializers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Django serializers for the event_sink_clickhouse app."""
import uuid

from django.utils import timezone
Expand All @@ -6,25 +7,35 @@
from event_sink_clickhouse.utils import get_model


class BaseSinkSerializer(serializers.Serializer):
class BaseSinkSerializer(serializers.Serializer): # pylint: disable=abstract-method
"""Base sink serializer for ClickHouse."""

dump_id = serializers.SerializerMethodField()
dump_timestamp = serializers.SerializerMethodField()

class Meta:
"""Meta class for base sink serializer."""

fields = [
"dump_id",
"dump_timestamp",
]

def get_dump_id(self, instance):
def get_dump_id(self, instance): # pylint: disable=unused-argument
"""Return a unique ID for the dump."""
return uuid.uuid4()

def get_dump_timestamp(self, instance):
def get_dump_timestamp(self, instance): # pylint: disable=unused-argument
"""Return the timestamp for the dump."""
return timezone.now()


class UserProfileSerializer(BaseSinkSerializer, serializers.ModelSerializer):
"""Serializer for user profile events."""

class Meta:
"""Meta class for user profile serializer."""

model = get_model("user_profile")
fields = [
"id",
Expand Down
8 changes: 4 additions & 4 deletions event_sink_clickhouse/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
from event_sink_clickhouse.utils import get_model


def receive_course_publish(
def receive_course_publish( # pylint: disable=unused-argument # pragma: no cover
sender, course_key, **kwargs
): # pylint: disable=unused-argument # pragma: no cover
):
"""
Receives COURSE_PUBLISHED signal and queues the dump job.
"""
Expand All @@ -20,9 +20,9 @@ def receive_course_publish(


@receiver(post_save, sender=get_model("user_profile"))
def on_user_profile_updated(
def on_user_profile_updated( # pylint: disable=unused-argument # pragma: no cover
sender, instance, **kwargs
): # pylint: disable=unused-argument # pragma: no cover
):
"""
Receives post save signal and queues the dump job.
"""
Expand Down
11 changes: 5 additions & 6 deletions event_sink_clickhouse/sinks/base_sink.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
import datetime
import io
import json
import uuid
from collections import namedtuple

import requests
from django.conf import settings
from django.utils import timezone

from event_sink_clickhouse.utils import get_model

Expand Down Expand Up @@ -114,7 +112,8 @@ def __init__(self, connection_overrides, log):

if not all(required_fields):
raise NotImplementedError(
"ModelBaseSink needs to be subclassed with model, clickhouse_table_name, timestamp_field, unique_key, and name"
"ModelBaseSink needs to be subclassed with model, clickhouse_table_name,"
"timestamp_field, unique_key, and name"
)

def get_model(self):
Expand Down Expand Up @@ -154,7 +153,7 @@ def serialize_item(self, item):
Serialize the data to be sent to ClickHouse
"""
Serializer = self.get_serializer()
serializer = Serializer(item)
serializer = Serializer(item) # pylint: disable=not-callable
return serializer.data

def get_serializer(self):
Expand Down Expand Up @@ -209,11 +208,11 @@ def fetch_target_items(self, ids=None, skip_ids=None, force_dump=False):
should_be_dumped, reason = self.should_dump_item(item_key)
yield item_key, should_be_dumped, reason

def should_dump_item(self, unique_key):
def should_dump_item(self, unique_key): # pylint: disable=unused-argument
"""
Return True if the item should be dumped to ClickHouse, False otherwise
"""
return True
return True, "No reason"

def get_last_dumped_timestamp(self, item_id):
"""
Expand Down
1 change: 1 addition & 0 deletions event_sink_clickhouse/sinks/user_profile_sink.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""User profile sink"""
from event_sink_clickhouse.serializers import UserProfileSerializer
from event_sink_clickhouse.sinks.base_sink import ModelBaseSink

Expand Down
2 changes: 2 additions & 0 deletions event_sink_clickhouse/utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
"""Utility functions for event_sink_clickhouse."""
from importlib import import_module

from django.conf import settings


def get_model(model_setting):
"""Load a model from a setting."""
MODEL_CONFIG = getattr(settings, "EVENT_SINK_CLICKHOUSE_MODEL_CONFIG", {})

model_config = getattr(MODEL_CONFIG, model_setting, {})
Expand Down

0 comments on commit eff0fc7

Please sign in to comment.