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

feat(samples): delete old test jobs #148

Merged
merged 4 commits into from
Feb 8, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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} =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a prefix we can check for as well on job.name? Otherwise I'm worried we might delete resources unintentionally.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately not. The job is a long-running operation where the server assigns a random name.

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