99
1010from apify_client ._consts import DEFAULT_WAIT_FOR_FINISH , DEFAULT_WAIT_WHEN_JOB_NOT_EXIST , ActorJobStatus
1111from apify_client ._logging import WithLogDetailsClient
12- from apify_client ._representations import to_seconds
13- from apify_client ._utils import catch_not_found_or_throw , response_to_dict , to_safe_id
12+ from apify_client ._utils import catch_not_found_or_throw , response_to_dict , to_safe_id , to_seconds
1413from apify_client .errors import ApifyApiError , ApifyClientError
1514
1615if TYPE_CHECKING :
@@ -171,7 +170,7 @@ def _wait_for_finish(
171170 )
172171 job_response = response_to_dict (response )
173172 job = job_response .get ('data' ) if isinstance (job_response , dict ) else job_response
174- seconds_elapsed = (datetime .now (timezone .utc ) - started_at ). total_seconds ( )
173+ seconds_elapsed = to_seconds (datetime .now (timezone .utc ) - started_at )
175174
176175 if not isinstance (job , dict ):
177176 raise ApifyClientError (
@@ -193,7 +192,7 @@ def _wait_for_finish(
193192
194193 # If there are still not found errors after DEFAULT_WAIT_WHEN_JOB_NOT_EXIST, we give up
195194 # and return None. In such case, the requested record probably really doesn't exist.
196- if seconds_elapsed > DEFAULT_WAIT_WHEN_JOB_NOT_EXIST . total_seconds ( ):
195+ if seconds_elapsed > to_seconds ( DEFAULT_WAIT_WHEN_JOB_NOT_EXIST ):
197196 return None
198197
199198 # It might take some time for database replicas to get up-to-date so sleep a bit before retrying
@@ -340,10 +339,10 @@ async def _wait_for_finish(
340339 should_repeat = True
341340 job : dict | None = None
342341 seconds_elapsed = 0.0
343- wait_secs = wait_duration . total_seconds () if wait_duration is not None else None
342+ wait_secs = to_seconds ( wait_duration )
344343
345344 while should_repeat :
346- wait_for_finish = int (DEFAULT_WAIT_FOR_FINISH . total_seconds () )
345+ wait_for_finish = to_seconds (DEFAULT_WAIT_FOR_FINISH )
347346 if wait_secs is not None :
348347 wait_for_finish = int (wait_secs - seconds_elapsed )
349348
@@ -362,7 +361,7 @@ async def _wait_for_finish(
362361 f'Expected dict with "status" field, got: { type (job ).__name__ } '
363362 )
364363
365- seconds_elapsed = (datetime .now (timezone .utc ) - started_at ). total_seconds ( )
364+ seconds_elapsed = to_seconds (datetime .now (timezone .utc ) - started_at )
366365 is_terminal = ActorJobStatus (job ['status' ]).is_terminal
367366 is_timed_out = wait_secs is not None and seconds_elapsed >= wait_secs
368367 if is_terminal or is_timed_out :
@@ -377,7 +376,7 @@ async def _wait_for_finish(
377376
378377 # If there are still not found errors after DEFAULT_WAIT_WHEN_JOB_NOT_EXIST, we give up
379378 # and return None. In such case, the requested record probably really doesn't exist.
380- if seconds_elapsed > DEFAULT_WAIT_WHEN_JOB_NOT_EXIST . total_seconds ( ):
379+ if seconds_elapsed > to_seconds ( DEFAULT_WAIT_WHEN_JOB_NOT_EXIST ):
381380 return None
382381
383382 # It might take some time for database replicas to get up-to-date so sleep a bit before retrying
0 commit comments