Skip to content

Commit

Permalink
Merge branch 'main' into inspect_table_string_augment_samples
Browse files Browse the repository at this point in the history
  • Loading branch information
pattishin authored Jul 27, 2023
2 parents 4840ef4 + 68a8a4d commit 27a3813
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 2 deletions.
2 changes: 1 addition & 1 deletion functions/billing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@google-cloud/billing": "^3.0.0",
"@google-cloud/compute": "^3.1.0",
"google-auth-library": "^8.0.0",
"googleapis": "^122.0.0",
"googleapis": "^123.0.0",
"slack": "^11.0.1"
},
"devDependencies": {
Expand Down
63 changes: 63 additions & 0 deletions media/transcoder/createJobFromPresetBatchMode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* Copyright 2023 Google LLC
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

function main(projectId, location, inputUri, outputUri, preset) {
// [START transcoder_create_job_from_preset_batch_mode]
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// projectId = 'my-project-id';
// location = 'us-central1';
// inputUri = 'gs://my-bucket/my-video-file';
// outputUri = 'gs://my-bucket/my-output-folder/';
// preset = 'preset/web-hd';

// Imports the Transcoder library
const {TranscoderServiceClient} =
require('@google-cloud/video-transcoder').v1;

// Instantiates a client
const transcoderServiceClient = new TranscoderServiceClient();

async function createJobFromPresetBatchMode() {
// Construct request
const request = {
parent: transcoderServiceClient.locationPath(projectId, location),
job: {
inputUri: inputUri,
outputUri: outputUri,
templateId: preset,
mode: 'PROCESSING_MODE_BATCH',
batchModePriority: 10,
},
};

// Run request
const [response] = await transcoderServiceClient.createJob(request);
console.log(`Job: ${response.name}`);
}

createJobFromPresetBatchMode();
// [END transcoder_create_job_from_preset_batch_mode]
}

// node createJobFromPresetBatchMode.js <projectId> <location> <inputUri> <outputUri> <preset>
process.on('unhandledRejection', err => {
console.error(err.message);
process.exitCode = 1;
});
main(...process.argv.slice(2));
2 changes: 1 addition & 1 deletion media/transcoder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"test": "c8 mocha --timeout 600000 test/*.js"
},
"dependencies": {
"@google-cloud/video-transcoder": "^2.2.3"
"@google-cloud/video-transcoder": "^2.7.0"
},
"devDependencies": {
"@google-cloud/storage": "^6.0.0",
Expand Down
58 changes: 58 additions & 0 deletions media/transcoder/test/transcoder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const captionsUri = `gs://${bucketName}/${testCaptionFileName}`;
const subtitles1Uri = `gs://${bucketName}/${testSubtitles1FileName}`;
const subtitles2Uri = `gs://${bucketName}/${testSubtitles2FileName}`;
const outputUriForPreset = `gs://${bucketName}/test-output-preset/`;
const outputUriForPresetBatchMode = `gs://${bucketName}/test-output-preset-batch-mode/`;
const outputUriForTemplate = `gs://${bucketName}/test-output-template/`;
const outputUriForAdHoc = `gs://${bucketName}/test-output-adhoc/`;
const outputUriForStaticOverlay = `gs://${bucketName}/test-output-static-overlay/`;
Expand Down Expand Up @@ -383,6 +384,63 @@ describe('Job functions adhoc', () => {
});
});

describe('Job functions preset batch mode', () => {
before(function () {
const output = execSync(
`node createJobFromPresetBatchMode.js ${projectId} ${location} ${inputUri} ${outputUriForPresetBatchMode} ${preset}`,
{cwd}
);
assert.ok(output.includes(`/locations/${location}/jobs/`));
this.presetBatchModeJobId = output.toString().split('/').pop();
});

after(function () {
const output = execSync(
`node deleteJob.js ${projectId} ${location} ${this.presetBatchModeJobId}`,
{cwd}
);
assert.ok(output.includes('Deleted job'));
});

it('should get a job', function () {
const output = execSync(
`node getJob.js ${projectId} ${location} ${this.presetBatchModeJobId}`,
{cwd}
);
const jobName = `/locations/${location}/jobs/${this.presetBatchModeJobId}`;
assert.ok(output.includes(jobName));
});

it('should show a list of jobs', function () {
const output = execSync(`node listJobs.js ${projectId} ${location}`, {
cwd,
});
const jobName = `/locations/${location}/jobs/${this.presetBatchModeJobId}`;
assert.ok(output.includes(jobName));
});

it('should check that the job succeeded', async function () {
this.retries(5);
await delay(this.test, 30000);

let getAttempts = 0;
while (getAttempts < 5) {
const ms = Math.pow(2, getAttempts + 1) * 10000 + Math.random() * 1000;
await wait(ms);
const output = execSync(
`node getJobState.js ${projectId} ${location} ${this.presetBatchModeJobId}`,
{cwd}
);
if (output.includes('Job state: SUCCEEDED')) {
assert.ok(true);
return;
}
getAttempts++;
}
assert.ok(false);
});
});

describe('Job with static overlay functions', () => {
before(function () {
const output = execSync(
Expand Down

0 comments on commit 27a3813

Please sign in to comment.