Skip to content

Commit 583af62

Browse files
committed
Update listen.ts
1 parent 510209b commit 583af62

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/lib/bin/commands/listen.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Command } from 'commander';
22

3-
import { BrowserUse } from '../../../';
3+
import { APIUserAbortError, BrowserUse } from '../../../';
44
import { createWebhookSignature, Webhook } from '../../webhooks';
55
import { createBrowserUseClient, getBrowserUseWebhookSecret } from '../auth';
66

@@ -34,6 +34,7 @@ export const listen = new Command('listen')
3434

3535
//
3636

37+
const startTimeDate = new Date();
3738
const queue: { current: Webhook[] } = { current: [] };
3839
const runs: Map<string, BrowserUse.TaskStatus> = new Map();
3940

@@ -51,13 +52,26 @@ export const listen = new Command('listen')
5152

5253
const tasks: BrowserUse.Tasks.TaskItemView[] = await client.tasks
5354
.list(
54-
{ pageSize: 10 },
55+
{
56+
pageSize: 10,
57+
// NOTE: There's a bug in the API where the datetime needs to be provided in naive format.cur
58+
after: startTimeDate.toISOString().replace('Z', ''),
59+
},
5560
{
5661
signal: tickRef.abort.signal,
5762
},
5863
)
5964
.then((res) => res.items)
60-
.catch((_) => []);
65+
.catch((err) => {
66+
if (err instanceof APIUserAbortError) {
67+
return [];
68+
}
69+
70+
console.log(`[polling] ${new Date().toISOString()} failed`);
71+
console.error(err);
72+
73+
return [];
74+
});
6175

6276
for (const task of tasks) {
6377
const currentTaskStatus = runs.get(task.id);

0 commit comments

Comments
 (0)