Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Cache HTTP responses #84

Merged
merged 4 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ jobs:
run: |
poetry env use ${{ matrix.python-version }}
poetry install
- name: Cache HTTP responses
uses: actions/cache@v4
with:
path: ~/.cache/tap-f1.sqlite
key: http-responses-${{ github.run_id }}
restore-keys: |
http-responses-
- name: Test with pytest
run: |
poetry run pytest
88 changes: 87 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ python = "^3.8"
singer-sdk = { version="~=0.42.1" }
fs-s3fs = { version = "~=1.1.1", optional = true }
requests = "~=2.32.3"
requests-cache = "^1.2.1"

[tool.poetry.group.dev.dependencies]
pytest = ">=7.4.0"
Expand All @@ -30,6 +31,8 @@ warn_unused_configs = true
[tool.ruff]
ignore = [
"ANN001", # missing-type-function-argument
"ANN002", # missing-type-args
"ANN003", # missing-type-kwargs
"ANN101", # missing-type-self
"ANN102", # missing-type-cls
"ANN201", # missing-return-type-undocumented-public-function
Expand Down
12 changes: 12 additions & 0 deletions tap_f1/client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
"""REST client handling, including F1Stream base class."""

from datetime import timedelta

from requests_cache import CachedSession
from singer_sdk.streams import RESTStream
from typing_extensions import override

Expand All @@ -12,6 +15,15 @@ class F1Stream(RESTStream):
url_base = "https://ergast.com/api/f1"
_limit = 1000

def __init__(self, *args, **kwargs) -> None:
"""Initialise the F1 stream."""
super().__init__(*args, **kwargs)
self._requests_session = CachedSession(
self.tap_name,
use_cache_dir=True,
expire_after=timedelta(days=1),
)

@override
def get_new_paginator(self):
return F1Paginator(0, self._limit)
Expand Down