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

Commit

Permalink
feat: add time-to-live in a queue for builds
Browse files Browse the repository at this point in the history
Co-authored-by: Alexander Fenster <fenster@google.com>
  • Loading branch information
yoshi-automation and alexander-fenster committed Mar 25, 2020
1 parent 84414b7 commit 04e3387
Show file tree
Hide file tree
Showing 15 changed files with 76 additions and 24 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
matrix:
node: [8, 10, 12, 13]
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
Expand All @@ -30,7 +30,7 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12
Expand All @@ -39,7 +39,7 @@ jobs:
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12
Expand All @@ -48,7 +48,7 @@ jobs:
coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 13
Expand Down
2 changes: 1 addition & 1 deletion .jsdoc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2019 Google LLC
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
11 changes: 10 additions & 1 deletion protos/google/devtools/cloudbuild/v1/cloudbuild.proto
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,13 @@ message Build {
// `FAILURE`.
repeated string images = 13;

// TTL in queue for this build. If provided and the build is enqueued longer
// than this value, the build will expire and the build status will be
// `EXPIRED`.
//
// The TTL starts ticking from create_time.
google.protobuf.Duration queue_ttl = 40;

// Artifacts produced by the build that should be uploaded upon
// successful completion of all build steps.
Artifacts artifacts = 37;
Expand Down Expand Up @@ -862,7 +869,9 @@ message BuildTrigger {
// If true, the trigger will never result in a build.
bool disabled = 9;

// Substitutions data for Build resource.
// Substitutions for Build resource. The keys must match the following
// regular expression: `^_[A-Z0-9_]+$`.The keys cannot conflict with the
// keys in bindings.
map<string, string> substitutions = 11;

// ignored_files and included_files are file glob matches using
Expand Down
6 changes: 6 additions & 0 deletions protos/protos.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1535,6 +1535,9 @@ export namespace google {
/** Build images */
images?: (string[]|null);

/** Build queueTtl */
queueTtl?: (google.protobuf.IDuration|null);

/** Build artifacts */
artifacts?: (google.devtools.cloudbuild.v1.IArtifacts|null);

Expand Down Expand Up @@ -1611,6 +1614,9 @@ export namespace google {
/** Build images. */
public images: string[];

/** Build queueTtl. */
public queueTtl?: (google.protobuf.IDuration|null);

/** Build artifacts. */
public artifacts?: (google.devtools.cloudbuild.v1.IArtifacts|null);

Expand Down
27 changes: 27 additions & 0 deletions protos/protos.js
Original file line number Diff line number Diff line change
Expand Up @@ -3635,6 +3635,7 @@
* @property {google.protobuf.ITimestamp|null} [finishTime] Build finishTime
* @property {google.protobuf.IDuration|null} [timeout] Build timeout
* @property {Array.<string>|null} [images] Build images
* @property {google.protobuf.IDuration|null} [queueTtl] Build queueTtl
* @property {google.devtools.cloudbuild.v1.IArtifacts|null} [artifacts] Build artifacts
* @property {string|null} [logsBucket] Build logsBucket
* @property {google.devtools.cloudbuild.v1.ISourceProvenance|null} [sourceProvenance] Build sourceProvenance
Expand Down Expand Up @@ -3764,6 +3765,14 @@
*/
Build.prototype.images = $util.emptyArray;

/**
* Build queueTtl.
* @member {google.protobuf.IDuration|null|undefined} queueTtl
* @memberof google.devtools.cloudbuild.v1.Build
* @instance
*/
Build.prototype.queueTtl = null;

/**
* Build artifacts.
* @member {google.devtools.cloudbuild.v1.IArtifacts|null|undefined} artifacts
Expand Down Expand Up @@ -3920,6 +3929,8 @@
}
if (message.artifacts != null && message.hasOwnProperty("artifacts"))
$root.google.devtools.cloudbuild.v1.Artifacts.encode(message.artifacts, writer.uint32(/* id 37, wireType 2 =*/298).fork()).ldelim();
if (message.queueTtl != null && message.hasOwnProperty("queueTtl"))
$root.google.protobuf.Duration.encode(message.queueTtl, writer.uint32(/* id 40, wireType 2 =*/322).fork()).ldelim();
return writer;
};

Expand Down Expand Up @@ -3994,6 +4005,9 @@
message.images = [];
message.images.push(reader.string());
break;
case 40:
message.queueTtl = $root.google.protobuf.Duration.decode(reader, reader.uint32());
break;
case 37:
message.artifacts = $root.google.devtools.cloudbuild.v1.Artifacts.decode(reader, reader.uint32());
break;
Expand Down Expand Up @@ -4143,6 +4157,11 @@
if (!$util.isString(message.images[i]))
return "images: string[] expected";
}
if (message.queueTtl != null && message.hasOwnProperty("queueTtl")) {
var error = $root.google.protobuf.Duration.verify(message.queueTtl);
if (error)
return "queueTtl." + error;
}
if (message.artifacts != null && message.hasOwnProperty("artifacts")) {
var error = $root.google.devtools.cloudbuild.v1.Artifacts.verify(message.artifacts);
if (error)
Expand Down Expand Up @@ -4307,6 +4326,11 @@
for (var i = 0; i < object.images.length; ++i)
message.images[i] = String(object.images[i]);
}
if (object.queueTtl != null) {
if (typeof object.queueTtl !== "object")
throw TypeError(".google.devtools.cloudbuild.v1.Build.queueTtl: object expected");
message.queueTtl = $root.google.protobuf.Duration.fromObject(object.queueTtl);
}
if (object.artifacts != null) {
if (typeof object.artifacts !== "object")
throw TypeError(".google.devtools.cloudbuild.v1.Build.artifacts: object expected");
Expand Down Expand Up @@ -4405,6 +4429,7 @@
object.statusDetail = "";
object.logUrl = "";
object.artifacts = null;
object.queueTtl = null;
}
if (message.id != null && message.hasOwnProperty("id"))
object.id = message.id;
Expand Down Expand Up @@ -4469,6 +4494,8 @@
}
if (message.artifacts != null && message.hasOwnProperty("artifacts"))
object.artifacts = $root.google.devtools.cloudbuild.v1.Artifacts.toObject(message.artifacts, options);
if (message.queueTtl != null && message.hasOwnProperty("queueTtl"))
object.queueTtl = $root.google.protobuf.Duration.toObject(message.queueTtl, options);
return object;
};

Expand Down
4 changes: 4 additions & 0 deletions protos/protos.json
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,10 @@
"type": "string",
"id": 13
},
"queueTtl": {
"type": "google.protobuf.Duration",
"id": 40
},
"artifacts": {
"type": "Artifacts",
"id": 37
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2019 Google LLC
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
12 changes: 9 additions & 3 deletions src/v1/cloud_build_client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2019 Google LLC
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -48,7 +48,12 @@ const version = require('../../../package.json').version;
* @memberof v1
*/
export class CloudBuildClient {
private _descriptors: Descriptors = {page: {}, stream: {}, longrunning: {}};
private _descriptors: Descriptors = {
page: {},
stream: {},
longrunning: {},
batching: {},
};
private _innerApiCalls: {[name: string]: Function};
private _terminated = false;
private _opts: ClientOptions;
Expand Down Expand Up @@ -290,7 +295,8 @@ export class CloudBuildClient {
if (this._terminated) {
return Promise.reject('The client has already been closed.');
}
return stub[methodName].apply(stub, args);
const func = stub[methodName];
return func.apply(stub, args);
},
(err: Error | null | undefined) => () => {
throw err;
Expand Down
2 changes: 1 addition & 1 deletion src/v1/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2019 Google LLC
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
Loading

0 comments on commit 04e3387

Please sign in to comment.