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

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 Feb 8, 2022
1 parent 23b8677 commit 4fb01da
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions samples/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 4fb01da

Please sign in to comment.