Edit on GitHub

sqlmesh.core.notification_target

 1from __future__ import annotations
 2
 3import sys
 4import typing as t
 5from enum import Enum
 6
 7from pydantic import Field
 8
 9from sqlmesh.core.console import Console, get_console
10from sqlmesh.utils.pydantic import PydanticModel
11
12if sys.version_info >= (3, 8):
13    from typing import Literal
14else:
15    from typing_extensions import Literal
16
17
18class NotificationStatus(str, Enum):
19    SUCCESS = "success"
20    FAILURE = "failure"
21    WARNING = "warning"
22    INFO = "info"
23    PROGRESS = "progress"
24
25    @property
26    def is_success(self) -> bool:
27        return self == NotificationStatus.SUCCESS
28
29    @property
30    def is_failure(self) -> bool:
31        return self == NotificationStatus.FAILURE
32
33    @property
34    def is_info(self) -> bool:
35        return self == NotificationStatus.INFO
36
37    @property
38    def is_warning(self) -> bool:
39        return self == NotificationStatus.WARNING
40
41    @property
42    def is_progress(self) -> bool:
43        return self == NotificationStatus.PROGRESS
44
45
46class BaseNotificationTarget(PydanticModel):
47    """
48    Base notification target model. Provides a command for sending notifications that is currently only used
49    by the built-in scheduler. Other schedulers like Airflow use the configuration of the target itself
50    to create the notification constructs appropriate for the scheduler.
51    """
52
53    type_: str
54
55    def send(self, notification_status: NotificationStatus, msg: str, **kwargs: t.Any) -> None:
56        """
57        Sends notification with the provided message. Currently only used by the built-in scheduler.
58        """
59
60
61class ConsoleNotificationTarget(BaseNotificationTarget):
62    """
63    Example console notification target. Keeping this around for testing purposes.
64    """
65
66    type_: Literal["console"] = Field(alias="type", default="console")
67    _console: t.Optional[Console] = None
68
69    @property
70    def console(self) -> Console:
71        if not self._console:
72            self._console = get_console()
73        return self._console
74
75    def send(self, notification_status: NotificationStatus, msg: str, **kwargs: t.Any) -> None:
76        if notification_status.is_success:
77            self.console.log_success(msg)
78        elif notification_status.is_failure:
79            self.console.log_error(msg)
80        else:
81            self.console.log_status_update(msg)
class NotificationStatus(builtins.str, enum.Enum):
19class NotificationStatus(str, Enum):
20    SUCCESS = "success"
21    FAILURE = "failure"
22    WARNING = "warning"
23    INFO = "info"
24    PROGRESS = "progress"
25
26    @property
27    def is_success(self) -> bool:
28        return self == NotificationStatus.SUCCESS
29
30    @property
31    def is_failure(self) -> bool:
32        return self == NotificationStatus.FAILURE
33
34    @property
35    def is_info(self) -> bool:
36        return self == NotificationStatus.INFO
37
38    @property
39    def is_warning(self) -> bool:
40        return self == NotificationStatus.WARNING
41
42    @property
43    def is_progress(self) -> bool:
44        return self == NotificationStatus.PROGRESS

An enumeration.

SUCCESS = <NotificationStatus.SUCCESS: 'success'>
FAILURE = <NotificationStatus.FAILURE: 'failure'>
WARNING = <NotificationStatus.WARNING: 'warning'>
INFO = <NotificationStatus.INFO: 'info'>
PROGRESS = <NotificationStatus.PROGRESS: 'progress'>
Inherited Members
enum.Enum
name
value
builtins.str
encode
replace
split
rsplit
join
capitalize
casefold
title
center
count
expandtabs
find
partition
index
ljust
lower
lstrip
rfind
rindex
rjust
rstrip
rpartition
splitlines
strip
swapcase
translate
upper
startswith
endswith
removeprefix
removesuffix
isascii
islower
isupper
istitle
isspace
isdecimal
isdigit
isnumeric
isalpha
isalnum
isidentifier
isprintable
zfill
format
format_map
maketrans
class BaseNotificationTarget(sqlmesh.utils.pydantic.PydanticModel):
47class BaseNotificationTarget(PydanticModel):
48    """
49    Base notification target model. Provides a command for sending notifications that is currently only used
50    by the built-in scheduler. Other schedulers like Airflow use the configuration of the target itself
51    to create the notification constructs appropriate for the scheduler.
52    """
53
54    type_: str
55
56    def send(self, notification_status: NotificationStatus, msg: str, **kwargs: t.Any) -> None:
57        """
58        Sends notification with the provided message. Currently only used by the built-in scheduler.
59        """

Base notification target model. Provides a command for sending notifications that is currently only used by the built-in scheduler. Other schedulers like Airflow use the configuration of the target itself to create the notification constructs appropriate for the scheduler.

def send( self, notification_status: sqlmesh.core.notification_target.NotificationStatus, msg: str, **kwargs: Any) -> None:
56    def send(self, notification_status: NotificationStatus, msg: str, **kwargs: t.Any) -> None:
57        """
58        Sends notification with the provided message. Currently only used by the built-in scheduler.
59        """

Sends notification with the provided message. Currently only used by the built-in scheduler.

Inherited Members
pydantic.main.BaseModel
BaseModel
parse_obj
parse_raw
parse_file
from_orm
construct
copy
schema
schema_json
validate
update_forward_refs
sqlmesh.utils.pydantic.PydanticModel
Config
dict
json
missing_required_fields
extra_fields
all_fields
required_fields
class ConsoleNotificationTarget(BaseNotificationTarget):
62class ConsoleNotificationTarget(BaseNotificationTarget):
63    """
64    Example console notification target. Keeping this around for testing purposes.
65    """
66
67    type_: Literal["console"] = Field(alias="type", default="console")
68    _console: t.Optional[Console] = None
69
70    @property
71    def console(self) -> Console:
72        if not self._console:
73            self._console = get_console()
74        return self._console
75
76    def send(self, notification_status: NotificationStatus, msg: str, **kwargs: t.Any) -> None:
77        if notification_status.is_success:
78            self.console.log_success(msg)
79        elif notification_status.is_failure:
80            self.console.log_error(msg)
81        else:
82            self.console.log_status_update(msg)

Example console notification target. Keeping this around for testing purposes.

def send( self, notification_status: sqlmesh.core.notification_target.NotificationStatus, msg: str, **kwargs: Any) -> None:
76    def send(self, notification_status: NotificationStatus, msg: str, **kwargs: t.Any) -> None:
77        if notification_status.is_success:
78            self.console.log_success(msg)
79        elif notification_status.is_failure:
80            self.console.log_error(msg)
81        else:
82            self.console.log_status_update(msg)

Sends notification with the provided message. Currently only used by the built-in scheduler.

Inherited Members
pydantic.main.BaseModel
BaseModel
parse_obj
parse_raw
parse_file
from_orm
construct
copy
schema
schema_json
validate
update_forward_refs
sqlmesh.utils.pydantic.PydanticModel
Config
dict
json
missing_required_fields
extra_fields
all_fields
required_fields