Skip to content

Commit

Permalink
fix custom components to run regression tests
Browse files Browse the repository at this point in the history
  • Loading branch information
brianjlai committed May 21, 2024
1 parent 8f4a1e7 commit 20d01e8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
)
from airbyte_cdk.sources.declarative.types import StreamSlice, StreamState
from source_freshdesk.utils import CallCredit
from sources.types import Record


@dataclass
Expand Down Expand Up @@ -121,15 +122,15 @@ class FreshdeskTicketsPaginationStrategy(PageIncrement):

PAGE_LIMIT = 300

def next_page_token(self, response: requests.Response, last_records: List[Mapping[str, Any]]) -> Optional[Any]:
def next_page_token(self, response: requests.Response, last_page_size: int, last_record: Optional[Record]) -> Optional[Any]:
# Stop paginating when there are fewer records than the page size or the current page has no records, or maximum page number is hit
if (self._page_size and len(last_records) < self._page_size) or len(last_records) == 0:
if (self._page_size and last_page_size < self._page_size) or last_page_size == 0:
return None
elif self._page >= self.PAGE_LIMIT:
# reset page count as cursor parameter will be updated in the stream slicer
self.reset()
# get last_record from latest batch, pos. -1, because of ACS order of records
last_record_updated_at = last_records[-1]["updated_at"]
last_record_updated_at = last_record["updated_at"]
# updating slicer request parameters with last_record state
return last_record_updated_at
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
from typing import Any, ClassVar, Iterable, Mapping, MutableMapping, Optional, Union

from airbyte_cdk.models import SyncMode
from airbyte_cdk.sources.declarative.incremental import Cursor
from airbyte_cdk.sources.declarative.incremental import DeclarativeCursor
from airbyte_cdk.sources.declarative.types import Record, StreamSlice, StreamState
from airbyte_cdk.sources.streams.core import Stream


@dataclass
class GreenHouseSlicer(Cursor):
class GreenHouseSlicer(DeclarativeCursor):
parameters: InitVar[Mapping[str, Any]]
cursor_field: str
request_cursor_field: str
Expand Down Expand Up @@ -94,6 +94,9 @@ def get_request_body_data(self, *args, **kwargs) -> Optional[Union[Mapping, str]
def get_request_body_json(self, *args, **kwargs) -> Optional[Mapping]:
return {}

def select_state(self, stream_slice: Optional[StreamSlice] = None) -> Optional[StreamState]:
return self.get_stream_state()


@dataclass
class GreenHouseSubstreamSlicer(GreenHouseSlicer):
Expand Down

0 comments on commit 20d01e8

Please sign in to comment.