File tree Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Original file line number Diff line number Diff line change 1
1
import { Command } from 'commander' ;
2
2
3
- import { BrowserUse } from '../../../' ;
3
+ import { APIUserAbortError , BrowserUse } from '../../../' ;
4
4
import { createWebhookSignature , Webhook } from '../../webhooks' ;
5
5
import { createBrowserUseClient , getBrowserUseWebhookSecret } from '../auth' ;
6
6
@@ -34,6 +34,7 @@ export const listen = new Command('listen')
34
34
35
35
//
36
36
37
+ const startTimeDate = new Date ( ) ;
37
38
const queue : { current : Webhook [ ] } = { current : [ ] } ;
38
39
const runs : Map < string , BrowserUse . TaskStatus > = new Map ( ) ;
39
40
@@ -51,13 +52,26 @@ export const listen = new Command('listen')
51
52
52
53
const tasks : BrowserUse . Tasks . TaskItemView [ ] = await client . tasks
53
54
. 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
+ } ,
55
60
{
56
61
signal : tickRef . abort . signal ,
57
62
} ,
58
63
)
59
64
. 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
+ } ) ;
61
75
62
76
for ( const task of tasks ) {
63
77
const currentTaskStatus = runs . get ( task . id ) ;
You can’t perform that action at this time.
0 commit comments