File: config.py

package info (click to toggle)
python-django-guid 3.5.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 664 kB
  • sloc: python: 1,267; makefile: 16
file content (43 lines) | stat: -rw-r--r-- 1,598 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# flake8: noqa: D102
from typing import TYPE_CHECKING

from django.core.exceptions import ImproperlyConfigured

from django_guid.integrations import SentryIntegration

if TYPE_CHECKING:
    from django_guid.integrations.celery import CeleryIntegration  # pragma: no cover


class CeleryIntegrationSettings:
    def __init__(self, instance: 'CeleryIntegration') -> None:
        self.instance = instance
        self.validate()

    @property
    def use_django_logging(self) -> bool:
        return self.instance.use_django_logging

    @property
    def log_parent(self) -> bool:
        return self.instance.log_parent

    @property
    def uuid_length(self) -> int:
        return self.instance.uuid_length

    @property
    def sentry_integration(self) -> bool:
        return self.instance.sentry_integration

    def validate(self) -> None:
        if not isinstance(self.use_django_logging, bool):
            raise ImproperlyConfigured('The CeleryIntegration use_django_logging setting must be a boolean.')
        if not isinstance(self.log_parent, bool):
            raise ImproperlyConfigured('The CeleryIntegration log_parent setting must be a boolean.')
        if type(self.uuid_length) is not int or not 1 <= self.uuid_length <= 32:
            raise ImproperlyConfigured('The CeleryIntegration uuid_length setting must be an integer.')
        if not isinstance(self.sentry_integration, bool):
            raise ImproperlyConfigured('The CeleryIntegration sentry_integration setting must be a boolean.')
        if self.sentry_integration:
            SentryIntegration().setup()