Skip to content

Commit 9bea0e1

Browse files
author
Richard Kuo (Onyx)
committed
more gc tweaks
1 parent f192e07 commit 9bea0e1

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

backend/onyx/connectors/salesforce/salesforce_calls.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,25 +139,29 @@ def _bulk_retrieve_from_salesforce(
139139

140140
query = _build_bulk_query(sf_client, sf_type, time_filter)
141141

142-
bulk_2_handler = SFBulk2Handler(
142+
bulk_2_handler: SFBulk2Handler | None = SFBulk2Handler(
143143
session_id=sf_client.session_id,
144144
bulk2_url=sf_client.bulk2_url,
145145
proxies=sf_client.proxies,
146146
session=sf_client.session,
147147
)
148+
if not bulk_2_handler:
149+
return sf_type, None
148150

149151
# NOTE(rkuo): there are signs this download is allocating large
150152
# amounts of memory instead of streaming the results to disk.
151153
# we're doing a gc.collect to try and mitigate this.
152154

153155
# see https://github.com/simple-salesforce/simple-salesforce/issues/428 for a
154156
# possible solution
155-
bulk_2_type = SFBulk2Type(
157+
bulk_2_type: SFBulk2Type | None = SFBulk2Type(
156158
object_name=sf_type,
157159
bulk2_url=bulk_2_handler.bulk2_url,
158160
headers=bulk_2_handler.headers,
159161
session=bulk_2_handler.session,
160162
)
163+
if not bulk_2_type:
164+
return sf_type, None
161165

162166
logger.info(f"Downloading {sf_type}")
163167

@@ -168,7 +172,7 @@ def _bulk_retrieve_from_salesforce(
168172
results = bulk_2_type.download(
169173
query=query,
170174
path=target_dir,
171-
max_records=1000000,
175+
max_records=500000,
172176
)
173177

174178
# prepend each downloaded csv with the object type (delimiter = '.')
@@ -187,6 +191,8 @@ def _bulk_retrieve_from_salesforce(
187191
logger.warning(f"Exceptioning query for object type {sf_type}: {query}")
188192
return sf_type, None
189193
finally:
194+
bulk_2_handler = None
195+
bulk_2_type = None
190196
gc.collect()
191197

192198
logger.info(f"Downloaded {sf_type} to {all_download_paths}")

0 commit comments

Comments
 (0)