Skip to content

Commit a8978ae

Browse files
refactor: inline retry using Retrying context manager
Eliminates the wrapper function that existed solely to carry the decorator. The Retrying context manager expresses the same intent inline without the extra indirection. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent d62a142 commit a8978ae

1 file changed

Lines changed: 12 additions & 25 deletions

File tree

cycode/cli/apps/scan/code_scanner.py

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import requests
77
import typer
8-
from tenacity import retry, retry_if_exception, stop_after_attempt, wait_random_exponential
8+
from tenacity import Retrying, retry_if_exception, stop_after_attempt, wait_random_exponential
99

1010
from cycode.cli import consts
1111
from cycode.cli.apps.scan.aggregation_report import try_set_aggregation_report_url_if_needed
@@ -34,7 +34,7 @@
3434
set_issue_detected_by_scan_results,
3535
should_use_presigned_upload,
3636
)
37-
from cycode.cyclient.models import ScanInitializationResponse, ZippedFileScanResult
37+
from cycode.cyclient.models import ZippedFileScanResult
3838
from cycode.logger import get_logger
3939

4040
if TYPE_CHECKING:
@@ -297,26 +297,6 @@ def scan_documents(
297297
print_local_scan_results(ctx, local_scan_results, errors)
298298

299299

300-
@retry(
301-
retry=retry_if_exception(lambda e: isinstance(e, RequestHttpError) and e.status_code == 404),
302-
stop=stop_after_attempt(3),
303-
wait=wait_random_exponential(multiplier=1, min=1, max=5),
304-
reraise=True,
305-
)
306-
def _notify_scan_from_upload_id(
307-
cycode_client: 'ScanClient',
308-
scan_type: str,
309-
upload_id: str,
310-
zipped_documents: 'InMemoryZip',
311-
scan_parameters: dict,
312-
is_git_diff: bool,
313-
is_commit_range: bool,
314-
) -> 'ScanInitializationResponse':
315-
return cycode_client.scan_repository_from_upload_id(
316-
scan_type, upload_id, zipped_documents, scan_parameters, is_git_diff, is_commit_range
317-
)
318-
319-
320300
def _perform_scan_v4_async(
321301
cycode_client: 'ScanClient',
322302
zipped_documents: 'InMemoryZip',
@@ -334,9 +314,16 @@ def _perform_scan_v4_async(
334314
)
335315
logger.debug('Uploaded zip to presigned URL')
336316

337-
scan_async_result = _notify_scan_from_upload_id(
338-
cycode_client, scan_type, upload_link.upload_id, zipped_documents, scan_parameters, is_git_diff, is_commit_range
339-
)
317+
for attempt in Retrying(
318+
retry=retry_if_exception(lambda e: isinstance(e, RequestHttpError) and e.status_code == 404),
319+
stop=stop_after_attempt(3),
320+
wait=wait_random_exponential(multiplier=1, min=1, max=5),
321+
reraise=True,
322+
):
323+
with attempt:
324+
scan_async_result = cycode_client.scan_repository_from_upload_id(
325+
scan_type, upload_link.upload_id, zipped_documents, scan_parameters, is_git_diff, is_commit_range
326+
)
340327
logger.debug(
341328
'Presigned upload scan request triggered, %s',
342329
{'scan_id': scan_async_result.scan_id, 'upload_id': upload_link.upload_id},

0 commit comments

Comments
 (0)