@@ -38,55 +38,40 @@ const outputUri = `gs://${bucketName}/test-output-channel/`;
3838const cwd = path . join ( __dirname , '..' ) ;
3939
4040before ( async ( ) => {
41- // Stop the channel if it already exists
42- try {
43- execSync ( `node stopChannel.js ${ projectId } ${ location } ${ channelId } ` , {
44- cwd,
45- } ) ;
46- } catch ( err ) {
47- // Ignore not found or not started error
48- }
49-
50- // Delete the channel if it already exists
51- try {
52- execSync ( `node deleteChannel.js ${ projectId } ${ location } ${ channelId } ` , {
53- cwd,
54- } ) ;
55- } catch ( err ) {
56- // Ignore not found error
57- }
58-
59- // Delete the default input if it already exists
60- try {
61- execSync ( `node deleteInput.js ${ projectId } ${ location } ${ inputId } ` , {
62- cwd,
63- } ) ;
64- } catch ( err ) {
65- // Ignore not found error
66- }
67- } ) ;
68-
69- after ( async ( ) => {
70- // Delete outstanding channels and inputs created more than 3 days ago
41+ // Delete outstanding channels and inputs created more than 3 hours ago
7142 const { LivestreamServiceClient} = require ( '@google-cloud/livestream' ) . v1 ;
7243 const livestreamServiceClient = new LivestreamServiceClient ( ) ;
73- const THREE_DAYS_IN_SEC = 60 * 60 * 24 * 3 ;
44+ const THREE_HOURS_IN_SEC = 60 * 60 * 3 ;
7445 const DATE_NOW_SEC = Math . floor ( Date . now ( ) / 1000 ) ;
7546
7647 const [ channels ] = await livestreamServiceClient . listChannels ( {
7748 parent : livestreamServiceClient . locationPath ( projectId , location ) ,
7849 } ) ;
7950 for ( const channel of channels ) {
80- if ( channel . createTime . seconds < DATE_NOW_SEC - THREE_DAYS_IN_SEC ) {
51+ if ( channel . createTime . seconds < DATE_NOW_SEC - THREE_HOURS_IN_SEC ) {
8152 const request = {
8253 name : channel . name ,
8354 } ;
8455 try {
85- await livestreamServiceClient . stopChannel ( request ) ;
56+ const [ operation ] = await livestreamServiceClient . stopChannel ( request ) ;
57+ await operation . promise ( ) ;
8658 } catch ( err ) {
8759 //Ignore error when channel is not started.
60+ console . log (
61+ 'Existing channel already stopped. Ignore the following error.'
62+ ) ;
8863 console . log ( err ) ;
8964 }
65+
66+ const [ events ] = await livestreamServiceClient . listEvents ( {
67+ parent : channel . name ,
68+ } ) ;
69+
70+ for ( const event of events ) {
71+ await livestreamServiceClient . deleteEvent ( {
72+ name : event . name ,
73+ } ) ;
74+ }
9075 await livestreamServiceClient . deleteChannel ( request ) ;
9176 }
9277 }
@@ -95,7 +80,7 @@ after(async () => {
9580 parent : livestreamServiceClient . locationPath ( projectId , location ) ,
9681 } ) ;
9782 for ( const input of inputs ) {
98- if ( input . createTime . seconds < DATE_NOW_SEC - THREE_DAYS_IN_SEC ) {
83+ if ( input . createTime . seconds < DATE_NOW_SEC - THREE_HOURS_IN_SEC ) {
9984 const request = {
10085 name : input . name ,
10186 } ;
0 commit comments