Skip to content

Commit

Permalink
Fix SSL SYSCALL error
Browse files Browse the repository at this point in the history
  • Loading branch information
elitonzky committed Mar 5, 2024
1 parent 2f7446c commit 9f63768
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions marketplace/services/vtex/generic_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from datetime import datetime

from django.db import close_old_connections
from django_redis import get_redis_connection

from dataclasses import dataclass
Expand Down Expand Up @@ -120,13 +121,16 @@ def first_product_insert(self, credentials: APICredentials, catalog: Catalog):
return None

products_csv = pvt_service.data_processor.products_to_csv(products)
close_old_connections()

Check warning on line 124 in marketplace/services/vtex/generic_service.py

View check run for this annotation

Codecov / codecov/patch

marketplace/services/vtex/generic_service.py#L124

Added line #L124 was not covered by tests
product_feed = self._send_products_to_facebook(products_csv, catalog)
pvt_service.data_processor.clear_csv_buffer(
products_csv
) # frees the memory of the csv file
close_old_connections()

Check warning on line 129 in marketplace/services/vtex/generic_service.py

View check run for this annotation

Codecov / codecov/patch

marketplace/services/vtex/generic_service.py#L129

Added line #L129 was not covered by tests
self.product_manager.create_or_update_products_on_database(
products, catalog, product_feed
)
close_old_connections()

Check warning on line 133 in marketplace/services/vtex/generic_service.py

View check run for this annotation

Codecov / codecov/patch

marketplace/services/vtex/generic_service.py#L133

Added line #L133 was not covered by tests
self.app_manager.initial_sync_products_completed(catalog.vtex_app)

return pvt_service.data_processor.convert_dtos_to_dicts_list(products)
Expand All @@ -146,6 +150,7 @@ def _send_products_to_facebook(self, products_csv, catalog: Catalog):
return product_feed

def _create_product_feed(self, name, catalog: Catalog) -> ProductFeed:
print("Creating the product feed")

Check warning on line 153 in marketplace/services/vtex/generic_service.py

View check run for this annotation

Codecov / codecov/patch

marketplace/services/vtex/generic_service.py#L153

Added line #L153 was not covered by tests
service = self.fb_service(catalog.app)
response = service.create_product_feed(catalog.facebook_catalog_id, name)

Expand All @@ -163,6 +168,7 @@ def _create_product_feed(self, name, catalog: Catalog) -> ProductFeed:
def _upload_product_feed(
self, app, product_feed_id, csv_file, file_name, update_only=False
):
print("Uploading the product feed to facebook")

Check warning on line 171 in marketplace/services/vtex/generic_service.py

View check run for this annotation

Codecov / codecov/patch

marketplace/services/vtex/generic_service.py#L171

Added line #L171 was not covered by tests
service = self.fb_service(app)
response = service.upload_product_feed(
product_feed_id, csv_file, file_name, "text/csv", update_only
Expand Down Expand Up @@ -234,6 +240,7 @@ def _webhook_update_products_on_facebook(self, products_csv) -> bool:
return True

def _webhook_upload_product_feed(self, csv_file, file_name: str) -> str:
print("Uploading the product feed to facebook")

Check warning on line 243 in marketplace/services/vtex/generic_service.py

View check run for this annotation

Codecov / codecov/patch

marketplace/services/vtex/generic_service.py#L243

Added line #L243 was not covered by tests
update_only = True
response = self.fba_service.upload_product_feed(
self.feed_id, csv_file, file_name, "text/csv", update_only
Expand Down
10 changes: 10 additions & 0 deletions marketplace/wpp_products/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from celery import shared_task

from django.db import reset_queries, close_old_connections

from marketplace.clients.facebook.client import FacebookClient
from marketplace.services.webhook.vtex.webhook_manager import WebhookQueueManager
from marketplace.wpp_products.models import Catalog
Expand Down Expand Up @@ -128,6 +130,12 @@ def task_insert_vtex_products(**kwargs):
return

try:
# Reset queries and close old connections for a clean state and performance.
# Prevents memory leak from stored queries and unstable database connections
# before further operations.
reset_queries()
close_old_connections()

catalog = Catalog.objects.get(uuid=catalog_uuid)
api_credentials = APICredentials(
app_key=credentials["app_key"],
Expand All @@ -145,6 +153,8 @@ def task_insert_vtex_products(**kwargs):
f"An error occurred during the first insertion of vtex products for catalog {catalog.name}, {e}"
)
return
finally:
close_old_connections()

try:
dict_catalog = {
Expand Down

0 comments on commit 9f63768

Please sign in to comment.