From 7792bf6c3cb3c203238d00ac7c2e18dc75ff2f56 Mon Sep 17 00:00:00 2001 From: Benjamin Coe Date: Thu, 23 Jan 2020 11:57:10 -0800 Subject: [PATCH 1/2] feat: allow pollIntervalMs to be configured --- package.json | 2 +- src/address.js | 1 + src/autoscaler.js | 1 + src/disk.js | 1 + src/firewall.js | 1 + src/health-check.js | 1 + src/image.js | 1 + src/index.js | 3 +++ src/instance-group-manager.js | 1 + src/instance-group.js | 1 + src/machine-type.js | 1 + src/network.js | 1 + src/operation.js | 3 +++ src/project.js | 1 + src/region.js | 2 ++ src/rule.js | 3 +++ src/service.js | 1 + src/snapshot.js | 1 + src/subnetwork.js | 1 + src/vm.js | 1 + src/zone.js | 1 + test/address.js | 1 + test/instance-group-manager.js | 4 +++- test/instance-group.js | 1 + test/machine-type.js | 1 + test/operation.js | 1 + test/subnetwork.js | 1 + 27 files changed, 36 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 513ef691..c60dda19 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "predocs-test": "npm run docs" }, "dependencies": { - "@google-cloud/common": "^2.0.0", + "@google-cloud/common": "^2.3.0", "@google-cloud/paginator": "^2.0.0", "@google-cloud/projectify": "^1.0.0", "@google-cloud/promisify": "^1.0.0", diff --git a/src/address.js b/src/address.js index ac8e3c30..637f2f79 100644 --- a/src/address.js +++ b/src/address.js @@ -162,6 +162,7 @@ class Address extends common.ServiceObject { id: name, createMethod: region.createAddress.bind(region), methods: methods, + pollIntervalMs: region.compute.pollIntervalMs }); /** * @name Address#name diff --git a/src/autoscaler.js b/src/autoscaler.js index d37b1308..849abd89 100644 --- a/src/autoscaler.js +++ b/src/autoscaler.js @@ -177,6 +177,7 @@ class Autoscaler extends common.ServiceObject { id: name, createMethod: zone.createAutoscaler.bind(zone), methods: methods, + pollIntervalMs: zone.compute.pollIntervalMs }); /** * @name Autoscaler#name diff --git a/src/disk.js b/src/disk.js index dc34a90d..d6f441c6 100644 --- a/src/disk.js +++ b/src/disk.js @@ -172,6 +172,7 @@ class Disk extends common.ServiceObject { id: name, createMethod: zone.createDisk.bind(zone), methods: methods, + pollIntervalMs: zone.compute.pollIntervalMs }); /** * @name Disk#name diff --git a/src/firewall.js b/src/firewall.js index 6b76b207..04dcb345 100644 --- a/src/firewall.js +++ b/src/firewall.js @@ -165,6 +165,7 @@ class Firewall extends common.ServiceObject { id: name, createMethod: compute.createFirewall.bind(compute), methods: methods, + pollIntervalMs: compute.pollIntervalMs }); /** * The parent {@link Compute} instance of this {@link Firewall} instance. diff --git a/src/health-check.js b/src/health-check.js index 153d3e64..c61c04fd 100644 --- a/src/health-check.js +++ b/src/health-check.js @@ -181,6 +181,7 @@ class HealthCheck extends common.ServiceObject { compute.createHealthCheck(name, options, callback); }, methods: methods, + pollIntervalMs: compute.pollIntervalMs }); /** * The parent {@link Compute} instance of this {@link HealthCheck} instance. diff --git a/src/image.js b/src/image.js index 4b134517..495f990e 100644 --- a/src/image.js +++ b/src/image.js @@ -156,6 +156,7 @@ class Image extends common.ServiceObject { id: name, createMethod: compute.createImage.bind(compute), methods: methods, + pollIntervalMs: compute.pollIntervalMs }); } /** diff --git a/src/index.js b/src/index.js index b639112c..829c665c 100644 --- a/src/index.js +++ b/src/index.js @@ -56,6 +56,8 @@ const Image = require('./image.js'); * We will exponentially backoff subsequent requests by default. * @property {number} [maxRetries=3] Maximum number of automatic retries * attempted before returning the error. + * @property {number} [pollIntervalMs=500] Poll interval for long running + * operations. * @property {Constructor} [promise] Custom promise module to use instead of * native Promises. * @property {string} [apiEndpoint] The API endpoint of the service used to make requests. Defaults to `compute.googleapis.com` @@ -88,6 +90,7 @@ class Compute extends common.Service { packageJson: require('../package.json'), }; super(config, options); + this.pollIntervalMs = options.pollIntervalMs; } /** * Create a firewall. diff --git a/src/instance-group-manager.js b/src/instance-group-manager.js index e1aa0119..64902b0b 100644 --- a/src/instance-group-manager.js +++ b/src/instance-group-manager.js @@ -140,6 +140,7 @@ class InstanceGroupManager extends common.ServiceObject { id: name, // createMethod: zone.createInstanceGroupManager.bind(zone), methods: methods, + pollIntervalMs: zone.compute.pollIntervalMs, }); /** * The parent {@link Zone} instance of this {@link InstanceGroup} instance. diff --git a/src/instance-group.js b/src/instance-group.js index 4ea3a2f5..049f616f 100644 --- a/src/instance-group.js +++ b/src/instance-group.js @@ -172,6 +172,7 @@ class InstanceGroup extends common.ServiceObject { id: name, createMethod: zone.createInstanceGroup.bind(zone), methods: methods, + pollIntervalMs: zone.compute.pollIntervalMs, }); /** * The parent {@link Zone} instance of this {@link InstanceGroup} instance. diff --git a/src/machine-type.js b/src/machine-type.js index ed55a6c3..39f0f541 100644 --- a/src/machine-type.js +++ b/src/machine-type.js @@ -128,6 +128,7 @@ class MachineType extends common.ServiceObject { */ id: name, methods: methods, + pollIntervalMs: zone.compute.pollIntervalMs, }); /** * The parent {@link Zone} instance of this {@link MachineType} instance. diff --git a/src/network.js b/src/network.js index 86220dd3..c31f5dee 100644 --- a/src/network.js +++ b/src/network.js @@ -167,6 +167,7 @@ class Network extends common.ServiceObject { id: name, createMethod: compute.createNetwork.bind(compute), methods: methods, + pollIntervalMs: compute.pollIntervalMs, }); /** * The parent {@link Compute} instance of this {@link Network} instance. diff --git a/src/operation.js b/src/operation.js index 7cf4e53c..e4732583 100644 --- a/src/operation.js +++ b/src/operation.js @@ -174,6 +174,9 @@ class Operation extends common.Operation { */ id: name, methods: methods, + pollIntervalMs: isCompute + ? scope.pollIntervalMs + : scope.compute.pollIntervalMs, }); /** diff --git a/src/project.js b/src/project.js index d6ad6aad..e263a014 100644 --- a/src/project.js +++ b/src/project.js @@ -95,6 +95,7 @@ class Project extends common.ServiceObject { baseUrl: '', id: '', methods: methods, + pollIntervalMs: compute.pollIntervalMs, }); } } diff --git a/src/region.js b/src/region.js index ecd356c4..3816d5e5 100644 --- a/src/region.js +++ b/src/region.js @@ -131,12 +131,14 @@ class Region extends common.ServiceObject { */ id: name, methods: methods, + pollIntervalMs: compute.pollIntervalMs, }); /** * @name Region#name * @type {string} */ this.name = name; + this.compute = compute; this.interceptors.push({ request: function(reqOpts) { if (reqOpts.uri.indexOf('/global/forwardingRules') > -1) { diff --git a/src/rule.js b/src/rule.js index 5328224a..b0bb148d 100644 --- a/src/rule.js +++ b/src/rule.js @@ -186,6 +186,9 @@ class Rule extends common.ServiceObject { id: name, createMethod: scope.createRule.bind(scope), methods: methods, + pollIntervalMs: scope.compute + ? scope.compute.pollIntervalMs + : scope.pollIntervalMs, }); /** * @name Rule#scope diff --git a/src/service.js b/src/service.js index ba075686..e828d520 100644 --- a/src/service.js +++ b/src/service.js @@ -181,6 +181,7 @@ class Service extends common.ServiceObject { id: name, createMethod: compute.createService.bind(compute), methods: methods, + pollIntervalMs: compute.pollIntervalMs, }); /** * The parent {@link Compute} instance of this {@link Service} instance. diff --git a/src/snapshot.js b/src/snapshot.js index 9d700a5c..807e2644 100644 --- a/src/snapshot.js +++ b/src/snapshot.js @@ -134,6 +134,7 @@ class Snapshot extends common.ServiceObject { */ id: name, methods: methods, + pollIntervalMs: compute.pollIntervalMs, }; if (isDisk) { config.createMethod = scope.createSnapshot.bind(scope); diff --git a/src/subnetwork.js b/src/subnetwork.js index 80fe79e9..10708d1d 100644 --- a/src/subnetwork.js +++ b/src/subnetwork.js @@ -168,6 +168,7 @@ class Subnetwork extends common.ServiceObject { id: name, createMethod: region.createSubnetwork.bind(region), methods: methods, + pollIntervalMs: region.compute.pollIntervalMs, }); /** * @name Subnetwork#name diff --git a/src/vm.js b/src/vm.js index 3c79e486..f2b42ec3 100644 --- a/src/vm.js +++ b/src/vm.js @@ -233,6 +233,7 @@ class VM extends common.ServiceObject { id: name, createMethod: zone.createVM.bind(zone), methods: methods, + pollIntervalMs: zone.compute.pollIntervalMs, }); /** diff --git a/src/zone.js b/src/zone.js index 3f965904..fa149793 100644 --- a/src/zone.js +++ b/src/zone.js @@ -138,6 +138,7 @@ class Zone extends common.ServiceObject { */ id: name, methods: methods, + pollIntervalMs: compute.pollIntervalMs, }); /** * The parent {@link Compute} instance of this {@link Zone} instance. diff --git a/test/address.js b/test/address.js index e0eb0064..bb5562dd 100644 --- a/test/address.js +++ b/test/address.js @@ -42,6 +42,7 @@ describe('Address', function() { const ADDRESS_NAME = 'us-central1'; const REGION = { createAddress: () => {}, + compute: {} }; before(function() { diff --git a/test/instance-group-manager.js b/test/instance-group-manager.js index a1f8952a..01439c42 100644 --- a/test/instance-group-manager.js +++ b/test/instance-group-manager.js @@ -41,7 +41,9 @@ describe('InstanceGroupManager', function() { const staticMethods = {}; - const ZONE = {}; + const ZONE = { + compute: {}, + }; const NAME = 'instance-group-manager-name'; before(function() { diff --git a/test/instance-group.js b/test/instance-group.js index b4b9fa4d..c70bd1c4 100644 --- a/test/instance-group.js +++ b/test/instance-group.js @@ -64,6 +64,7 @@ describe('InstanceGroup', function() { const ZONE = { createInstanceGroup: util.noop, vm: util.noop, + compute: {}, }; const NAME = 'instance-group-name'; diff --git a/test/machine-type.js b/test/machine-type.js index 7e8931af..18495c25 100644 --- a/test/machine-type.js +++ b/test/machine-type.js @@ -31,6 +31,7 @@ describe('MachineType', function() { const ZONE_NAME = 'zone-1'; const ZONE = { name: ZONE_NAME, + compute: {}, }; const MACHINE_TYPE_NAME = 'g1-small'; diff --git a/test/operation.js b/test/operation.js index faa660c8..9b976e0f 100644 --- a/test/operation.js +++ b/test/operation.js @@ -56,6 +56,7 @@ describe('Operation', function() { const SCOPE = { Promise: Promise, + compute: {}, }; const OPERATION_NAME = 'operation-name'; diff --git a/test/subnetwork.js b/test/subnetwork.js index 2f698562..474b9c63 100644 --- a/test/subnetwork.js +++ b/test/subnetwork.js @@ -44,6 +44,7 @@ describe('Subnetwork', function() { const REGION = { createSubnetwork: util.noop, name: REGION_NAME, + compute: {}, }; before(function() { From e2f55dc23b778896da1389e7675d74a2faebc1b0 Mon Sep 17 00:00:00 2001 From: Benjamin Coe Date: Thu, 23 Jan 2020 12:30:59 -0800 Subject: [PATCH 2/2] chore: fix linting --- src/address.js | 2 +- src/autoscaler.js | 2 +- src/disk.js | 2 +- src/firewall.js | 2 +- src/health-check.js | 2 +- src/image.js | 2 +- test/address.js | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/address.js b/src/address.js index 637f2f79..7ff95bb3 100644 --- a/src/address.js +++ b/src/address.js @@ -162,7 +162,7 @@ class Address extends common.ServiceObject { id: name, createMethod: region.createAddress.bind(region), methods: methods, - pollIntervalMs: region.compute.pollIntervalMs + pollIntervalMs: region.compute.pollIntervalMs, }); /** * @name Address#name diff --git a/src/autoscaler.js b/src/autoscaler.js index 849abd89..62e794b4 100644 --- a/src/autoscaler.js +++ b/src/autoscaler.js @@ -177,7 +177,7 @@ class Autoscaler extends common.ServiceObject { id: name, createMethod: zone.createAutoscaler.bind(zone), methods: methods, - pollIntervalMs: zone.compute.pollIntervalMs + pollIntervalMs: zone.compute.pollIntervalMs, }); /** * @name Autoscaler#name diff --git a/src/disk.js b/src/disk.js index d6f441c6..7a758b2e 100644 --- a/src/disk.js +++ b/src/disk.js @@ -172,7 +172,7 @@ class Disk extends common.ServiceObject { id: name, createMethod: zone.createDisk.bind(zone), methods: methods, - pollIntervalMs: zone.compute.pollIntervalMs + pollIntervalMs: zone.compute.pollIntervalMs, }); /** * @name Disk#name diff --git a/src/firewall.js b/src/firewall.js index 04dcb345..313de548 100644 --- a/src/firewall.js +++ b/src/firewall.js @@ -165,7 +165,7 @@ class Firewall extends common.ServiceObject { id: name, createMethod: compute.createFirewall.bind(compute), methods: methods, - pollIntervalMs: compute.pollIntervalMs + pollIntervalMs: compute.pollIntervalMs, }); /** * The parent {@link Compute} instance of this {@link Firewall} instance. diff --git a/src/health-check.js b/src/health-check.js index c61c04fd..6825d98a 100644 --- a/src/health-check.js +++ b/src/health-check.js @@ -181,7 +181,7 @@ class HealthCheck extends common.ServiceObject { compute.createHealthCheck(name, options, callback); }, methods: methods, - pollIntervalMs: compute.pollIntervalMs + pollIntervalMs: compute.pollIntervalMs, }); /** * The parent {@link Compute} instance of this {@link HealthCheck} instance. diff --git a/src/image.js b/src/image.js index 495f990e..35c650ba 100644 --- a/src/image.js +++ b/src/image.js @@ -156,7 +156,7 @@ class Image extends common.ServiceObject { id: name, createMethod: compute.createImage.bind(compute), methods: methods, - pollIntervalMs: compute.pollIntervalMs + pollIntervalMs: compute.pollIntervalMs, }); } /** diff --git a/test/address.js b/test/address.js index bb5562dd..ff6891d8 100644 --- a/test/address.js +++ b/test/address.js @@ -42,7 +42,7 @@ describe('Address', function() { const ADDRESS_NAME = 'us-central1'; const REGION = { createAddress: () => {}, - compute: {} + compute: {}, }; before(function() {