Skip to content

Commit

Permalink
feat(samples): delete old test jobs (#148)
Browse files Browse the repository at this point in the history
Co-authored-by: Takashi Matsuo <tmatsuo@google.com>
  • Loading branch information
irataxy and Takashi Matsuo committed Jan 18, 2023
1 parent cb2510a commit eb0b253
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions media/transcoder/test/transcoder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,24 @@ after(async () => {
} catch (err) {
console.log('Cannot delete bucket');
}
// Delete outstanding jobs created more than 3 days ago
const {TranscoderServiceClient} =
require('@google-cloud/video-transcoder').v1;
const transcoderServiceClient = new TranscoderServiceClient();
const [jobs] = await transcoderServiceClient.listJobs({
parent: transcoderServiceClient.locationPath(projectId, location),
});
const THREE_DAYS_IN_SEC = 60 * 60 * 24 * 3;
const DATE_NOW_SEC = Math.floor(Date.now() / 1000);

for (const job of jobs) {
if (job.createTime.seconds < DATE_NOW_SEC - THREE_DAYS_IN_SEC) {
const request = {
name: job.name,
};
await transcoderServiceClient.deleteJob(request);
}
}
});

describe('Job template functions', () => {
Expand Down

0 comments on commit eb0b253

Please sign in to comment.