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

HGI-6654/ Improve request time and increase default results_per_page #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
improve request time by keep the connection opened in the session. cl…
…ose the session after finish. increase default results_per_page
arilton committed Oct 24, 2024
commit 4ffde447a82cab0d52fdac658a7f6011b8de16d1
6 changes: 5 additions & 1 deletion tap_shopify/__init__.py
Original file line number Diff line number Diff line change
@@ -33,6 +33,7 @@ def initialize_shopify_client():
version = Context.config.get('api_version', '2024-01')
session = shopify.Session(shop, version, api_key)
shopify.ShopifyResource.activate_session(session)
shopify.ShopifyResource._headers['Connection'] = 'keep-alive'
# Shop.current() makes a call for shop details with provided shop and api_key
return shopify.Shop.current().attributes

@@ -183,7 +184,7 @@ def sync():

Context.state['bookmarks'].pop('currently_sync_stream')
singer.write_state(Context.state)

LOGGER.info('----------------------')
for stream_id, stream_count in Context.counts.items():
LOGGER.info('%s: %d', stream_id, stream_count)
@@ -226,6 +227,9 @@ def main():
raise ShopifyError(exc, msg) from exc
except Exception as exc:
raise ShopifyError(exc) from exc
finally:
shopify.ShopifyResource.clear_session()


if __name__ == "__main__":
main()
4 changes: 3 additions & 1 deletion tap_shopify/context.py
Original file line number Diff line number Diff line change
@@ -3,6 +3,8 @@

LOGGER = singer.get_logger()

RESULTS_PER_PAGE = 250

class Context():
config = {}
state = {}
@@ -27,7 +29,7 @@ def is_selected(cls, stream_name):
def get_results_per_page(cls, default_results_per_page):
results_per_page = default_results_per_page
try:
results_per_page = int(cls.config.get("results_per_page"))
results_per_page = int(cls.config.get("results_per_page", RESULTS_PER_PAGE))
except TypeError:
# None value or no key
pass
6 changes: 2 additions & 4 deletions tap_shopify/streams/base.py
Original file line number Diff line number Diff line change
@@ -9,17 +9,15 @@
import simplejson
import singer
from singer import metrics, utils
from tap_shopify.context import Context
from tap_shopify.context import Context, RESULTS_PER_PAGE

LOGGER = singer.get_logger()

RESULTS_PER_PAGE = 175

# We've observed 500 errors returned if this is too large (30 days was too
# large for a customer)
DATE_WINDOW_SIZE = 365

# We will retry a 500 error a maximum of 5 times before giving up
# We will retry a 500 error a maximum of 10 times before giving up
MAX_RETRIES = 10

def is_not_status_code_fn(status_code):
1 change: 0 additions & 1 deletion tap_shopify/streams/inventory_items.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import singer
import shopify
from singer.utils import strftime,strptime_to_utc
from tap_shopify.streams.base import (Stream, shopify_error_handling)
from tap_shopify.context import Context