Skip to content
This repository was archived by the owner on Jul 20, 2023. It is now read-only.

Commit ad94ca0

Browse files
irataxyTakashi Matsuo
andauthored
feat(samples): delete old test jobs (#148)
Co-authored-by: Takashi Matsuo <tmatsuo@google.com>
1 parent 02a9c0e commit ad94ca0

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

samples/test/transcoder.test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,24 @@ after(async () => {
127127
} catch (err) {
128128
console.log('Cannot delete bucket');
129129
}
130+
// Delete outstanding jobs created more than 3 days ago
131+
const {TranscoderServiceClient} =
132+
require('@google-cloud/video-transcoder').v1;
133+
const transcoderServiceClient = new TranscoderServiceClient();
134+
const [jobs] = await transcoderServiceClient.listJobs({
135+
parent: transcoderServiceClient.locationPath(projectId, location),
136+
});
137+
const THREE_DAYS_IN_SEC = 60 * 60 * 24 * 3;
138+
const DATE_NOW_SEC = Math.floor(Date.now() / 1000);
139+
140+
for (const job of jobs) {
141+
if (job.createTime.seconds < DATE_NOW_SEC - THREE_DAYS_IN_SEC) {
142+
const request = {
143+
name: job.name,
144+
};
145+
await transcoderServiceClient.deleteJob(request);
146+
}
147+
}
130148
});
131149

132150
describe('Job template functions', () => {

0 commit comments

Comments
 (0)