Skip to content

Commit dfac06c

Browse files
Centralize started-job context construction across managers
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent aa51579 commit dfac06c

26 files changed

Lines changed: 224 additions & 140 deletions

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ This runs lint, format checks, compile checks, tests, and package build.
107107
- `tests/test_readme_examples_listing.py` (README example-listing consistency enforcement),
108108
- `tests/test_session_profile_update_helper_usage.py` (session profile-update parameter helper usage enforcement),
109109
- `tests/test_session_upload_helper_usage.py` (session upload-input normalization helper usage enforcement),
110+
- `tests/test_start_job_context_helper_usage.py` (shared started-job context helper usage enforcement),
110111
- `tests/test_tool_mapping_reader_usage.py` (tools mapping-helper usage),
111112
- `tests/test_type_utils_usage.py` (type `__mro__` boundary centralization in `hyperbrowser/type_utils.py`),
112113
- `tests/test_web_pagination_internal_reuse.py` (web pagination helper internal reuse of shared job pagination helpers),

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

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

3-
from ....polling import (
4-
build_operation_name,
5-
ensure_started_job_id,
6-
wait_for_job_result_async,
7-
)
3+
from ....polling import wait_for_job_result_async
84
from ....schema_utils import resolve_schema_input
95
from ...response_utils import parse_response_model
106
from ...serialization_utils import serialize_model_dump_to_dict
7+
from ...start_job_utils import build_started_job_context
118

129
from .....models import (
1310
POLLING_ATTEMPTS,
@@ -82,11 +79,11 @@ async def start_and_wait(
8279
max_status_failures: int = POLLING_ATTEMPTS,
8380
) -> BrowserUseTaskResponse:
8481
job_start_resp = await self.start(params)
85-
job_id = ensure_started_job_id(
86-
job_start_resp.job_id,
87-
error_message="Failed to start browser-use task job",
82+
job_id, operation_name = build_started_job_context(
83+
started_job_id=job_start_resp.job_id,
84+
start_error_message="Failed to start browser-use task job",
85+
operation_name_prefix="browser-use task job ",
8886
)
89-
operation_name = build_operation_name("browser-use task job ", job_id)
9087

9188
return await wait_for_job_result_async(
9289
operation_name=operation_name,

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

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

3-
from ....polling import (
4-
build_operation_name,
5-
ensure_started_job_id,
6-
wait_for_job_result_async,
7-
)
3+
from ....polling import wait_for_job_result_async
84
from ...response_utils import parse_response_model
95
from ...serialization_utils import serialize_model_dump_to_dict
6+
from ...start_job_utils import build_started_job_context
107

118
from .....models import (
129
POLLING_ATTEMPTS,
@@ -77,11 +74,11 @@ async def start_and_wait(
7774
max_status_failures: int = POLLING_ATTEMPTS,
7875
) -> ClaudeComputerUseTaskResponse:
7976
job_start_resp = await self.start(params)
80-
job_id = ensure_started_job_id(
81-
job_start_resp.job_id,
82-
error_message="Failed to start Claude Computer Use task job",
77+
job_id, operation_name = build_started_job_context(
78+
started_job_id=job_start_resp.job_id,
79+
start_error_message="Failed to start Claude Computer Use task job",
80+
operation_name_prefix="Claude Computer Use task job ",
8381
)
84-
operation_name = build_operation_name("Claude Computer Use task job ", job_id)
8582

8683
return await wait_for_job_result_async(
8784
operation_name=operation_name,

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

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

3-
from ....polling import (
4-
build_operation_name,
5-
ensure_started_job_id,
6-
wait_for_job_result_async,
7-
)
3+
from ....polling import wait_for_job_result_async
84
from ...response_utils import parse_response_model
95
from ...serialization_utils import serialize_model_dump_to_dict
6+
from ...start_job_utils import build_started_job_context
107

118
from .....models import (
129
POLLING_ATTEMPTS,
@@ -75,11 +72,11 @@ async def start_and_wait(
7572
max_status_failures: int = POLLING_ATTEMPTS,
7673
) -> CuaTaskResponse:
7774
job_start_resp = await self.start(params)
78-
job_id = ensure_started_job_id(
79-
job_start_resp.job_id,
80-
error_message="Failed to start CUA task job",
75+
job_id, operation_name = build_started_job_context(
76+
started_job_id=job_start_resp.job_id,
77+
start_error_message="Failed to start CUA task job",
78+
operation_name_prefix="CUA task job ",
8179
)
82-
operation_name = build_operation_name("CUA task job ", job_id)
8380

8481
return await wait_for_job_result_async(
8582
operation_name=operation_name,

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

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

3-
from ....polling import (
4-
build_operation_name,
5-
ensure_started_job_id,
6-
wait_for_job_result_async,
7-
)
3+
from ....polling import wait_for_job_result_async
84
from ...response_utils import parse_response_model
95
from ...serialization_utils import serialize_model_dump_to_dict
6+
from ...start_job_utils import build_started_job_context
107

118
from .....models import (
129
POLLING_ATTEMPTS,
@@ -77,11 +74,11 @@ async def start_and_wait(
7774
max_status_failures: int = POLLING_ATTEMPTS,
7875
) -> GeminiComputerUseTaskResponse:
7976
job_start_resp = await self.start(params)
80-
job_id = ensure_started_job_id(
81-
job_start_resp.job_id,
82-
error_message="Failed to start Gemini Computer Use task job",
77+
job_id, operation_name = build_started_job_context(
78+
started_job_id=job_start_resp.job_id,
79+
start_error_message="Failed to start Gemini Computer Use task job",
80+
operation_name_prefix="Gemini Computer Use task job ",
8381
)
84-
operation_name = build_operation_name("Gemini Computer Use task job ", job_id)
8582

8683
return await wait_for_job_result_async(
8784
operation_name=operation_name,

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

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

3-
from ....polling import (
4-
build_operation_name,
5-
ensure_started_job_id,
6-
wait_for_job_result_async,
7-
)
3+
from ....polling import wait_for_job_result_async
84
from ...response_utils import parse_response_model
95
from ...serialization_utils import serialize_model_dump_to_dict
6+
from ...start_job_utils import build_started_job_context
107

118
from .....models import (
129
POLLING_ATTEMPTS,
@@ -77,11 +74,11 @@ async def start_and_wait(
7774
max_status_failures: int = POLLING_ATTEMPTS,
7875
) -> HyperAgentTaskResponse:
7976
job_start_resp = await self.start(params)
80-
job_id = ensure_started_job_id(
81-
job_start_resp.job_id,
82-
error_message="Failed to start HyperAgent task",
77+
job_id, operation_name = build_started_job_context(
78+
started_job_id=job_start_resp.job_id,
79+
start_error_message="Failed to start HyperAgent task",
80+
operation_name_prefix="HyperAgent task ",
8381
)
84-
operation_name = build_operation_name("HyperAgent task ", job_id)
8582

8683
return await wait_for_job_result_async(
8784
operation_name=operation_name,

hyperbrowser/client/managers/async_manager/crawl.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
from hyperbrowser.models.consts import POLLING_ATTEMPTS
44
from ...polling import (
55
build_fetch_operation_name,
6-
build_operation_name,
76
collect_paginated_results_async,
8-
ensure_started_job_id,
97
poll_until_terminal_status_async,
108
retry_operation_async,
119
)
@@ -19,6 +17,7 @@
1917
serialize_model_dump_to_dict,
2018
)
2119
from ..response_utils import parse_response_model
20+
from ..start_job_utils import build_started_job_context
2221
from ....models.crawl import (
2322
CrawlJobResponse,
2423
CrawlJobStatusResponse,
@@ -84,11 +83,11 @@ async def start_and_wait(
8483
max_status_failures: int = POLLING_ATTEMPTS,
8584
) -> CrawlJobResponse:
8685
job_start_resp = await self.start(params)
87-
job_id = ensure_started_job_id(
88-
job_start_resp.job_id,
89-
error_message="Failed to start crawl job",
86+
job_id, operation_name = build_started_job_context(
87+
started_job_id=job_start_resp.job_id,
88+
start_error_message="Failed to start crawl job",
89+
operation_name_prefix="crawl job ",
9090
)
91-
operation_name = build_operation_name("crawl job ", job_id)
9291

9392
job_status = await poll_until_terminal_status_async(
9493
operation_name=operation_name,

hyperbrowser/client/managers/async_manager/extract.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,9 @@
77
StartExtractJobParams,
88
StartExtractJobResponse,
99
)
10-
from ...polling import (
11-
build_operation_name,
12-
ensure_started_job_id,
13-
wait_for_job_result_async,
14-
)
1510
from ..extract_payload_utils import build_extract_start_payload
11+
from ..start_job_utils import build_started_job_context
12+
from ...polling import wait_for_job_result_async
1613
from ..response_utils import parse_response_model
1714

1815

@@ -61,11 +58,11 @@ async def start_and_wait(
6158
max_status_failures: int = POLLING_ATTEMPTS,
6259
) -> ExtractJobResponse:
6360
job_start_resp = await self.start(params)
64-
job_id = ensure_started_job_id(
65-
job_start_resp.job_id,
66-
error_message="Failed to start extract job",
61+
job_id, operation_name = build_started_job_context(
62+
started_job_id=job_start_resp.job_id,
63+
start_error_message="Failed to start extract job",
64+
operation_name_prefix="extract job ",
6765
)
68-
operation_name = build_operation_name("extract job ", job_id)
6966

7067
return await wait_for_job_result_async(
7168
operation_name=operation_name,

hyperbrowser/client/managers/async_manager/scrape.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
from hyperbrowser.models.consts import POLLING_ATTEMPTS
44
from ...polling import (
55
build_fetch_operation_name,
6-
build_operation_name,
76
collect_paginated_results_async,
8-
ensure_started_job_id,
97
poll_until_terminal_status_async,
108
retry_operation_async,
119
wait_for_job_result_async,
@@ -20,6 +18,7 @@
2018
serialize_model_dump_to_dict,
2119
)
2220
from ..response_utils import parse_response_model
21+
from ..start_job_utils import build_started_job_context
2322
from ....models.scrape import (
2423
BatchScrapeJobResponse,
2524
BatchScrapeJobStatusResponse,
@@ -91,11 +90,11 @@ async def start_and_wait(
9190
max_status_failures: int = POLLING_ATTEMPTS,
9291
) -> BatchScrapeJobResponse:
9392
job_start_resp = await self.start(params)
94-
job_id = ensure_started_job_id(
95-
job_start_resp.job_id,
96-
error_message="Failed to start batch scrape job",
93+
job_id, operation_name = build_started_job_context(
94+
started_job_id=job_start_resp.job_id,
95+
start_error_message="Failed to start batch scrape job",
96+
operation_name_prefix="batch scrape job ",
9797
)
98-
operation_name = build_operation_name("batch scrape job ", job_id)
9998

10099
job_status = await poll_until_terminal_status_async(
101100
operation_name=operation_name,
@@ -196,11 +195,11 @@ async def start_and_wait(
196195
max_status_failures: int = POLLING_ATTEMPTS,
197196
) -> ScrapeJobResponse:
198197
job_start_resp = await self.start(params)
199-
job_id = ensure_started_job_id(
200-
job_start_resp.job_id,
201-
error_message="Failed to start scrape job",
198+
job_id, operation_name = build_started_job_context(
199+
started_job_id=job_start_resp.job_id,
200+
start_error_message="Failed to start scrape job",
201+
operation_name_prefix="scrape job ",
202202
)
203-
operation_name = build_operation_name("scrape job ", job_id)
204203

205204
return await wait_for_job_result_async(
206205
operation_name=operation_name,

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@
1717
)
1818
from ....polling import (
1919
build_fetch_operation_name,
20-
build_operation_name,
2120
collect_paginated_results_async,
22-
ensure_started_job_id,
2321
poll_until_terminal_status_async,
2422
retry_operation_async,
2523
)
2624
from ...response_utils import parse_response_model
25+
from ...start_job_utils import build_started_job_context
2726

2827

2928
class BatchFetchManager:
@@ -78,11 +77,11 @@ async def start_and_wait(
7877
max_status_failures: int = POLLING_ATTEMPTS,
7978
) -> BatchFetchJobResponse:
8079
job_start_resp = await self.start(params)
81-
job_id = ensure_started_job_id(
82-
job_start_resp.job_id,
83-
error_message="Failed to start batch fetch job",
80+
job_id, operation_name = build_started_job_context(
81+
started_job_id=job_start_resp.job_id,
82+
start_error_message="Failed to start batch fetch job",
83+
operation_name_prefix="batch fetch job ",
8484
)
85-
operation_name = build_operation_name("batch fetch job ", job_id)
8685

8786
job_status = await poll_until_terminal_status_async(
8887
operation_name=operation_name,

0 commit comments

Comments
 (0)