Skip to content

Commit

Permalink
Change redis connection
Browse files Browse the repository at this point in the history
  • Loading branch information
elitonzky committed May 10, 2024
1 parent 54b485a commit 598d9e6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
5 changes: 3 additions & 2 deletions marketplace/clients/vtex/decorator.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import functools
import time
import requests
from redis import Redis

from django_redis import get_redis_connection


class RateLimiter:
Expand Down Expand Up @@ -83,7 +84,7 @@ def rate_limit_and_retry_on_exception(
"""

def decorator(func):
redis_connection = Redis(host="localhost", port=6379, db=0)
redis_connection = get_redis_connection()
seconds_limiter = RateLimiter("per_sec", calls_per_second, 1, redis_connection)
minute_limiter = RateLimiter("per_min", calls_per_minute, 60, redis_connection)

Expand Down
4 changes: 3 additions & 1 deletion marketplace/services/product/product_facebook_manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ def save_first_csv_product_data(

# Step 1: Delete existing products for the catalog
deleted_count, _ = UploadProduct.objects.filter(catalog=catalog).delete()
print(f"Deleted {deleted_count} existing products for catalog {catalog.id}")
print(

Check warning on line 148 in marketplace/services/product/product_facebook_manage.py

View check run for this annotation

Codecov / codecov/patch

marketplace/services/product/product_facebook_manage.py#L147-L148

Added lines #L147 - L148 were not covered by tests
f"Deleted {deleted_count} existing products for catalog {catalog.facebook_catalog_id}"
)

# Step 2: Prepare data for bulk create
products_to_create = []
Expand Down
14 changes: 7 additions & 7 deletions marketplace/services/vtex/generic_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,13 @@ def first_product_insert(
# TODO: --END: This block needs to be removed--

# TODO: --BEGIN: This block will replace the block above--
all_success = self.product_manager.save_first_csv_product_data(
products, catalog, pvt_service.data_processor
)
if not all_success:
raise Exception(
f"Error on save first csv on database. Catalog:{self.catalog.facebook_catalog_id}"
)
# all_success = self.product_manager.save_first_csv_product_data(
# products, catalog, product_feed,pvt_service.data_processor
# )
# if not all_success:
# raise Exception(
# f"Error on save first csv on database. Catalog:{self.catalog.facebook_catalog_id}"
# )
# TODO --END: This block will replace the block above-
close_old_connections()
self.app_manager.initial_sync_products_completed(catalog.vtex_app)
Expand Down

0 comments on commit 598d9e6

Please sign in to comment.