-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathrunner.py
57 lines (45 loc) · 1.46 KB
/
runner.py
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
#
import logging
from abc import ABC, abstractmethod
from typing import Generic, Iterable, Optional
from airbyte_cdk.connector import TConfig
from airbyte_cdk.models import (
AirbyteCatalog,
AirbyteMessage,
AirbyteStateMessage,
ConfiguredAirbyteCatalog,
ConnectorSpecification,
)
from airbyte_cdk.sources.source import Source
class SourceRunner(ABC, Generic[TConfig]):
@abstractmethod
def spec(self) -> ConnectorSpecification:
pass
@abstractmethod
def discover(self, config: TConfig) -> AirbyteCatalog:
pass
@abstractmethod
def read(
self,
config: TConfig,
catalog: ConfiguredAirbyteCatalog,
state: Optional[AirbyteStateMessage],
) -> Iterable[AirbyteMessage]:
pass
class CDKRunner(SourceRunner[TConfig]):
def __init__(self, source: Source, name: str):
self._source = source
self._logger = logging.getLogger(name)
def spec(self) -> ConnectorSpecification:
return self._source.spec(self._logger)
def discover(self, config: TConfig) -> AirbyteCatalog:
return self._source.discover(self._logger, config)
def read(
self,
config: TConfig,
catalog: ConfiguredAirbyteCatalog,
state: Optional[AirbyteStateMessage],
) -> Iterable[AirbyteMessage]:
return self._source.read(self._logger, config, catalog, state=[state] if state else [])