Skip to content

Commit 1b53d59

Browse files
Centralize started job-id normalization in managers
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent f4f791a commit 1b53d59

File tree

22 files changed

+255
-96
lines changed

22 files changed

+255
-96
lines changed

hyperbrowser/client/managers/async_manager/agents/browser_use.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
from typing import Optional
22

3-
from hyperbrowser.exceptions import HyperbrowserError
4-
from ....polling import build_operation_name, wait_for_job_result_async
3+
from ....polling import (
4+
build_operation_name,
5+
ensure_started_job_id,
6+
wait_for_job_result_async,
7+
)
58
from ....schema_utils import resolve_schema_input
69
from ...response_utils import parse_response_model
710

@@ -75,9 +78,10 @@ async def start_and_wait(
7578
max_status_failures: int = POLLING_ATTEMPTS,
7679
) -> BrowserUseTaskResponse:
7780
job_start_resp = await self.start(params)
78-
job_id = job_start_resp.job_id
79-
if not job_id:
80-
raise HyperbrowserError("Failed to start browser-use task job")
81+
job_id = ensure_started_job_id(
82+
job_start_resp.job_id,
83+
error_message="Failed to start browser-use task job",
84+
)
8185
operation_name = build_operation_name("browser-use task job ", job_id)
8286

8387
return await wait_for_job_result_async(

hyperbrowser/client/managers/async_manager/agents/claude_computer_use.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
from typing import Optional
22

3-
from hyperbrowser.exceptions import HyperbrowserError
4-
from ....polling import build_operation_name, wait_for_job_result_async
3+
from ....polling import (
4+
build_operation_name,
5+
ensure_started_job_id,
6+
wait_for_job_result_async,
7+
)
58
from ...response_utils import parse_response_model
69

710
from .....models import (
@@ -69,9 +72,10 @@ async def start_and_wait(
6972
max_status_failures: int = POLLING_ATTEMPTS,
7073
) -> ClaudeComputerUseTaskResponse:
7174
job_start_resp = await self.start(params)
72-
job_id = job_start_resp.job_id
73-
if not job_id:
74-
raise HyperbrowserError("Failed to start Claude Computer Use task job")
75+
job_id = ensure_started_job_id(
76+
job_start_resp.job_id,
77+
error_message="Failed to start Claude Computer Use task job",
78+
)
7579
operation_name = build_operation_name("Claude Computer Use task job ", job_id)
7680

7781
return await wait_for_job_result_async(

hyperbrowser/client/managers/async_manager/agents/cua.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
from typing import Optional
22

3-
from hyperbrowser.exceptions import HyperbrowserError
4-
from ....polling import build_operation_name, wait_for_job_result_async
3+
from ....polling import (
4+
build_operation_name,
5+
ensure_started_job_id,
6+
wait_for_job_result_async,
7+
)
58
from ...response_utils import parse_response_model
69

710
from .....models import (
@@ -67,9 +70,10 @@ async def start_and_wait(
6770
max_status_failures: int = POLLING_ATTEMPTS,
6871
) -> CuaTaskResponse:
6972
job_start_resp = await self.start(params)
70-
job_id = job_start_resp.job_id
71-
if not job_id:
72-
raise HyperbrowserError("Failed to start CUA task job")
73+
job_id = ensure_started_job_id(
74+
job_start_resp.job_id,
75+
error_message="Failed to start CUA task job",
76+
)
7377
operation_name = build_operation_name("CUA task job ", job_id)
7478

7579
return await wait_for_job_result_async(

hyperbrowser/client/managers/async_manager/agents/gemini_computer_use.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
from typing import Optional
22

3-
from hyperbrowser.exceptions import HyperbrowserError
4-
from ....polling import build_operation_name, wait_for_job_result_async
3+
from ....polling import (
4+
build_operation_name,
5+
ensure_started_job_id,
6+
wait_for_job_result_async,
7+
)
58
from ...response_utils import parse_response_model
69

710
from .....models import (
@@ -69,9 +72,10 @@ async def start_and_wait(
6972
max_status_failures: int = POLLING_ATTEMPTS,
7073
) -> GeminiComputerUseTaskResponse:
7174
job_start_resp = await self.start(params)
72-
job_id = job_start_resp.job_id
73-
if not job_id:
74-
raise HyperbrowserError("Failed to start Gemini Computer Use task job")
75+
job_id = ensure_started_job_id(
76+
job_start_resp.job_id,
77+
error_message="Failed to start Gemini Computer Use task job",
78+
)
7579
operation_name = build_operation_name("Gemini Computer Use task job ", job_id)
7680

7781
return await wait_for_job_result_async(

hyperbrowser/client/managers/async_manager/agents/hyper_agent.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
from typing import Optional
22

3-
from hyperbrowser.exceptions import HyperbrowserError
4-
from ....polling import build_operation_name, wait_for_job_result_async
3+
from ....polling import (
4+
build_operation_name,
5+
ensure_started_job_id,
6+
wait_for_job_result_async,
7+
)
58
from ...response_utils import parse_response_model
69

710
from .....models import (
@@ -69,9 +72,10 @@ async def start_and_wait(
6972
max_status_failures: int = POLLING_ATTEMPTS,
7073
) -> HyperAgentTaskResponse:
7174
job_start_resp = await self.start(params)
72-
job_id = job_start_resp.job_id
73-
if not job_id:
74-
raise HyperbrowserError("Failed to start HyperAgent task")
75+
job_id = ensure_started_job_id(
76+
job_start_resp.job_id,
77+
error_message="Failed to start HyperAgent task",
78+
)
7579
operation_name = build_operation_name("HyperAgent task ", job_id)
7680

7781
return await wait_for_job_result_async(

hyperbrowser/client/managers/async_manager/crawl.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
build_fetch_operation_name,
66
build_operation_name,
77
collect_paginated_results_async,
8+
ensure_started_job_id,
89
poll_until_terminal_status_async,
910
retry_operation_async,
1011
)
@@ -16,7 +17,6 @@
1617
StartCrawlJobParams,
1718
StartCrawlJobResponse,
1819
)
19-
from ....exceptions import HyperbrowserError
2020

2121

2222
class CrawlManager:
@@ -67,9 +67,10 @@ async def start_and_wait(
6767
max_status_failures: int = POLLING_ATTEMPTS,
6868
) -> CrawlJobResponse:
6969
job_start_resp = await self.start(params)
70-
job_id = job_start_resp.job_id
71-
if not job_id:
72-
raise HyperbrowserError("Failed to start crawl job")
70+
job_id = ensure_started_job_id(
71+
job_start_resp.job_id,
72+
error_message="Failed to start crawl job",
73+
)
7374
operation_name = build_operation_name("crawl job ", job_id)
7475

7576
job_status = await poll_until_terminal_status_async(

hyperbrowser/client/managers/async_manager/extract.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
StartExtractJobParams,
99
StartExtractJobResponse,
1010
)
11-
from ...polling import build_operation_name, wait_for_job_result_async
11+
from ...polling import (
12+
build_operation_name,
13+
ensure_started_job_id,
14+
wait_for_job_result_async,
15+
)
1216
from ...schema_utils import resolve_schema_input
1317
from ..response_utils import parse_response_model
1418

@@ -63,9 +67,10 @@ async def start_and_wait(
6367
max_status_failures: int = POLLING_ATTEMPTS,
6468
) -> ExtractJobResponse:
6569
job_start_resp = await self.start(params)
66-
job_id = job_start_resp.job_id
67-
if not job_id:
68-
raise HyperbrowserError("Failed to start extract job")
70+
job_id = ensure_started_job_id(
71+
job_start_resp.job_id,
72+
error_message="Failed to start extract job",
73+
)
6974
operation_name = build_operation_name("extract job ", job_id)
7075

7176
return await wait_for_job_result_async(

hyperbrowser/client/managers/async_manager/scrape.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
build_fetch_operation_name,
66
build_operation_name,
77
collect_paginated_results_async,
8+
ensure_started_job_id,
89
poll_until_terminal_status_async,
910
retry_operation_async,
1011
wait_for_job_result_async,
@@ -21,7 +22,6 @@
2122
StartScrapeJobParams,
2223
StartScrapeJobResponse,
2324
)
24-
from ....exceptions import HyperbrowserError
2525

2626

2727
class BatchScrapeManager:
@@ -74,9 +74,10 @@ async def start_and_wait(
7474
max_status_failures: int = POLLING_ATTEMPTS,
7575
) -> BatchScrapeJobResponse:
7676
job_start_resp = await self.start(params)
77-
job_id = job_start_resp.job_id
78-
if not job_id:
79-
raise HyperbrowserError("Failed to start batch scrape job")
77+
job_id = ensure_started_job_id(
78+
job_start_resp.job_id,
79+
error_message="Failed to start batch scrape job",
80+
)
8081
operation_name = build_operation_name("batch scrape job ", job_id)
8182

8283
job_status = await poll_until_terminal_status_async(
@@ -180,9 +181,10 @@ async def start_and_wait(
180181
max_status_failures: int = POLLING_ATTEMPTS,
181182
) -> ScrapeJobResponse:
182183
job_start_resp = await self.start(params)
183-
job_id = job_start_resp.job_id
184-
if not job_id:
185-
raise HyperbrowserError("Failed to start scrape job")
184+
job_id = ensure_started_job_id(
185+
job_start_resp.job_id,
186+
error_message="Failed to start scrape job",
187+
)
186188
operation_name = build_operation_name("scrape job ", job_id)
187189

188190
return await wait_for_job_result_async(

hyperbrowser/client/managers/async_manager/web/batch_fetch.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
BatchFetchJobResponse,
99
POLLING_ATTEMPTS,
1010
)
11-
from hyperbrowser.exceptions import HyperbrowserError
1211
from ....polling import (
1312
build_fetch_operation_name,
1413
build_operation_name,
1514
collect_paginated_results_async,
15+
ensure_started_job_id,
1616
poll_until_terminal_status_async,
1717
retry_operation_async,
1818
)
@@ -75,9 +75,10 @@ async def start_and_wait(
7575
max_status_failures: int = POLLING_ATTEMPTS,
7676
) -> BatchFetchJobResponse:
7777
job_start_resp = await self.start(params)
78-
job_id = job_start_resp.job_id
79-
if not job_id:
80-
raise HyperbrowserError("Failed to start batch fetch job")
78+
job_id = ensure_started_job_id(
79+
job_start_resp.job_id,
80+
error_message="Failed to start batch fetch job",
81+
)
8182
operation_name = build_operation_name("batch fetch job ", job_id)
8283

8384
job_status = await poll_until_terminal_status_async(

hyperbrowser/client/managers/async_manager/web/crawl.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
WebCrawlJobResponse,
99
POLLING_ATTEMPTS,
1010
)
11-
from hyperbrowser.exceptions import HyperbrowserError
1211
from ....polling import (
1312
build_fetch_operation_name,
1413
build_operation_name,
1514
collect_paginated_results_async,
15+
ensure_started_job_id,
1616
poll_until_terminal_status_async,
1717
retry_operation_async,
1818
)
@@ -73,9 +73,10 @@ async def start_and_wait(
7373
max_status_failures: int = POLLING_ATTEMPTS,
7474
) -> WebCrawlJobResponse:
7575
job_start_resp = await self.start(params)
76-
job_id = job_start_resp.job_id
77-
if not job_id:
78-
raise HyperbrowserError("Failed to start web crawl job")
76+
job_id = ensure_started_job_id(
77+
job_start_resp.job_id,
78+
error_message="Failed to start web crawl job",
79+
)
7980
operation_name = build_operation_name("web crawl job ", job_id)
8081

8182
job_status = await poll_until_terminal_status_async(

0 commit comments

Comments
 (0)