Skip to content

Commit 25238cb

Browse files
authored
Use config registry waiters in docs (#601)
Co-authored-by: Sayan- <1415138+Sayan-@users.noreply.github.com>
1 parent cec5a3d commit 25238cb

1 file changed

Lines changed: 9 additions & 21 deletions

File tree

‎config-registry.mdx‎

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: "Find browser and proxy settings that can reach the site you want t
55

66
**status:** <Badge color="yellow">preview</Badge>
77

8-
give the config registry a public url and it returns browser and proxy settings that have worked for that site. if we don't have a recommendation yet, you can start an analysis against the live site and poll for the result.
8+
give the config registry a public url and it returns browser and proxy settings that have worked for that site. if we don't have a recommendation yet, you can start an analysis against the live site and wait for the result.
99

1010
recommendations are advisory. you decide whether to use them, and <span className="kernel-brand-name">KERNEL</span> won't create a browser or proxy until you ask it to.
1111

@@ -44,7 +44,7 @@ a null `recommendation` means the registry doesn't have a usable answer for this
4444

4545
### 2. run an analysis when needed
4646

47-
`resolve` starts an analysis or joins one already running for the same url. analysis usually takes several minutes. the initial response has a null `recommendation`, so poll the returned analysis id until its status is no longer `running`.
47+
`resolve` starts an analysis or joins one already running for the same url. analysis usually takes several minutes. the initial response has a null `recommendation`, so pass the returned analysis id to the sdk waiter.
4848

4949
<CodeGroup>
5050

@@ -53,11 +53,7 @@ const started = await kernel.configRegistry.resolve({
5353
url: 'https://www.kernel.sh/docs',
5454
});
5555

56-
let result = started;
57-
while (result.analysis?.status === 'running') {
58-
await new Promise((resolve) => setTimeout(resolve, 5000));
59-
result = await kernel.configRegistry.analyses.retrieve(started.analysis!.id);
60-
}
56+
const result = await kernel.configRegistry.analyses.waitForResult(started.analysis!.id);
6157

6258
if (result.recommendation?.type === 'recommendation') {
6359
console.log(result.recommendation);
@@ -69,10 +65,7 @@ if (result.recommendation?.type === 'recommendation') {
6965
```python Python
7066
started = kernel.config_registry.resolve(url="https://www.kernel.sh/docs")
7167

72-
result = started
73-
while result.analysis and result.analysis.status == "running":
74-
time.sleep(5)
75-
result = kernel.config_registry.analyses.retrieve(started.analysis.id)
68+
result = kernel.config_registry.analyses.wait_for_result(started.analysis.id)
7669

7770
if result.recommendation and result.recommendation.type == "recommendation":
7871
print(result.recommendation)
@@ -82,6 +75,8 @@ else:
8275

8376
</CodeGroup>
8477

78+
the waiters poll every five seconds by default. use `maxWaitMs` in typescript or `max_wait_seconds` in python to bound the local wait. timing out stops waiting but doesn't cancel the analysis.
79+
8580
the terminal analysis statuses are `completed`, `failed`, `canceled`, and `expired`. when an analysis finishes without a recommendation, inspect `recommendation` and `analysis.failure` for the reason and retry guidance.
8681

8782
### 3. create a browser with the recommendation
@@ -146,7 +141,7 @@ the dashboard generates equivalent typescript, python, and cli snippets for each
146141
| method | use it when | behavior |
147142
| --- | --- | --- |
148143
| `lookup` | you want the best answer already in the registry | returns immediately, doesn't start work, and always reflects current knowledge |
149-
| `resolve` | `lookup` returned null or you want fresh evidence | starts or joins an analysis and returns an analysis id to poll |
144+
| `resolve` | `lookup` returned null or you want fresh evidence | starts or joins an analysis and returns an analysis id to pass to the sdk waiter |
150145

151146
a completed analysis is a stable historical record. retrieving its id always returns what that run concluded, even after later analyses produce new knowledge. use `lookup` when you want the latest recommendation instead.
152147

@@ -200,11 +195,7 @@ an analysis may also return short guidance based on what it observed while navig
200195

201196
```typescript TypeScript
202197
// assuming you've started an analysis
203-
let result = started;
204-
while (result.analysis?.status === 'running') {
205-
await new Promise((resolve) => setTimeout(resolve, 5000));
206-
result = await kernel.configRegistry.analyses.retrieve(started.analysis!.id);
207-
}
198+
const result = await kernel.configRegistry.analyses.waitForResult(started.analysis!.id);
208199

209200
if (result.guidance) {
210201
console.log(result.guidance);
@@ -213,10 +204,7 @@ if (result.guidance) {
213204

214205
```python Python
215206
# assuming you've started an analysis
216-
result = started
217-
while result.analysis and result.analysis.status == "running":
218-
time.sleep(5)
219-
result = kernel.config_registry.analyses.retrieve(started.analysis.id)
207+
result = kernel.config_registry.analyses.wait_for_result(started.analysis.id)
220208

221209
if result.guidance:
222210
print(result.guidance)

0 commit comments

Comments
 (0)