UNPKG

@google-cloud/tasks

Version:
946 lines (920 loc) 139 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CloudTasksClient = void 0; var _googleGax = _interopRequireWildcard(require("google-gax")); var gax = _googleGax; var _path = _interopRequireDefault(require("path")); var _url = require("url"); var _jsonHelper = require("../json-helper.cjs"); function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; } function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); } function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); } function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } } function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } } function _arrayWithHoles(r) { if (Array.isArray(r)) return r; } function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); } function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } } function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; } function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } // Copyright 2025 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 // // https://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. // // ** This file is automatically generated by gapic-generator-typescript. ** // ** https://github.com/googleapis/gapic-generator-typescript ** // ** All changes to this file may be overwritten. ** /* global window */ // @ts-ignore // @ts-ignore var dirname = __dirname; /** * Client JSON configuration object, loaded from * `src/v2beta2/cloud_tasks_client_config.json`. * This file defines retry strategy and timeouts for all API methods in this library. */ var gapicConfig = (0, _jsonHelper.getJSON)(_path["default"].join(dirname, 'cloud_tasks_client_config.json')); var jsonProtos = (0, _jsonHelper.getJSON)(_path["default"].join(dirname, '..', '..', '..', 'protos/protos.json')); var version = (0, _jsonHelper.getJSON)(_path["default"].join(dirname, '..', '..', '..', '..', 'package.json')).version; /** * Cloud Tasks allows developers to manage the execution of background * work in their applications. * @class * @memberof v2beta2 */ var CloudTasksClient = exports.CloudTasksClient = /*#__PURE__*/function () { /** * Construct an instance of CloudTasksClient. * * @param {object} [options] - The configuration object. * The options accepted by the constructor are described in detail * in [this document](https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#creating-the-client-instance). * The common options are: * @param {object} [options.credentials] - Credentials object. * @param {string} [options.credentials.client_email] * @param {string} [options.credentials.private_key] * @param {string} [options.email] - Account email address. Required when * using a .pem or .p12 keyFilename. * @param {string} [options.keyFilename] - Full path to the a .json, .pem, or * .p12 key downloaded from the Google Developers Console. If you provide * a path to a JSON file, the projectId option below is not necessary. * NOTE: .pem and .p12 require you to specify options.email as well. * @param {number} [options.port] - The port on which to connect to * the remote host. * @param {string} [options.projectId] - The project ID from the Google * Developer's Console, e.g. 'grape-spaceship-123'. We will also check * the environment variable GCLOUD_PROJECT for your project ID. If your * app is running in an environment which supports * {@link https://cloud.google.com/docs/authentication/application-default-credentials Application Default Credentials}, * your project ID will be detected automatically. * @param {string} [options.apiEndpoint] - The domain name of the * API remote host. * @param {gax.ClientConfig} [options.clientConfig] - Client configuration override. * Follows the structure of {@link gapicConfig}. * @param {boolean | "rest"} [options.fallback] - Use HTTP fallback mode. * Pass "rest" to use HTTP/1.1 REST API instead of gRPC. * For more information, please check the * {@link https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#http11-rest-api-mode documentation}. * @param {gax} [gaxInstance]: loaded instance of `google-gax`. Useful if you * need to avoid loading the default gRPC version and want to use the fallback * HTTP implementation. Load only fallback version and pass it to the constructor: * ``` * const gax = require('google-gax/build/src/fallback'); // avoids loading google-gax with gRPC * const client = new CloudTasksClient({fallback: 'rest'}, gax); * ``` */ function CloudTasksClient(opts, gaxInstance) { var _opts, _opts2, _opts3, _opts4, _ref, _ref2, _opts$universeDomain, _opts5, _opts6, _opts7, _opts8, _opts9, _opts0, _opts1, _opts$clientConfig, _opts10, _opts$fallback, _opts11, _window; _classCallCheck(this, CloudTasksClient); _defineProperty(this, "_terminated", false); _defineProperty(this, "_opts", void 0); _defineProperty(this, "_providedCustomServicePath", void 0); _defineProperty(this, "_gaxModule", void 0); _defineProperty(this, "_gaxGrpc", void 0); _defineProperty(this, "_protos", void 0); _defineProperty(this, "_defaults", void 0); _defineProperty(this, "_universeDomain", void 0); _defineProperty(this, "_servicePath", void 0); _defineProperty(this, "_log", _googleGax.loggingUtils.log('tasks')); _defineProperty(this, "auth", void 0); _defineProperty(this, "descriptors", { page: {}, stream: {}, longrunning: {}, batching: {} }); _defineProperty(this, "warn", void 0); _defineProperty(this, "innerApiCalls", void 0); _defineProperty(this, "locationsClient", void 0); _defineProperty(this, "pathTemplates", void 0); _defineProperty(this, "cloudTasksStub", void 0); // Ensure that options include all the required fields. var staticMembers = this.constructor; if ((_opts = opts) !== null && _opts !== void 0 && _opts.universe_domain && (_opts2 = opts) !== null && _opts2 !== void 0 && _opts2.universeDomain && ((_opts3 = opts) === null || _opts3 === void 0 ? void 0 : _opts3.universe_domain) !== ((_opts4 = opts) === null || _opts4 === void 0 ? void 0 : _opts4.universeDomain)) { throw new Error('Please set either universe_domain or universeDomain, but not both.'); } var universeDomainEnvVar = (typeof process === "undefined" ? "undefined" : _typeof(process)) === 'object' && _typeof(process.env) === 'object' ? process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] : undefined; this._universeDomain = (_ref = (_ref2 = (_opts$universeDomain = (_opts5 = opts) === null || _opts5 === void 0 ? void 0 : _opts5.universeDomain) !== null && _opts$universeDomain !== void 0 ? _opts$universeDomain : (_opts6 = opts) === null || _opts6 === void 0 ? void 0 : _opts6.universe_domain) !== null && _ref2 !== void 0 ? _ref2 : universeDomainEnvVar) !== null && _ref !== void 0 ? _ref : 'googleapis.com'; this._servicePath = 'cloudtasks.' + this._universeDomain; var servicePath = ((_opts7 = opts) === null || _opts7 === void 0 ? void 0 : _opts7.servicePath) || ((_opts8 = opts) === null || _opts8 === void 0 ? void 0 : _opts8.apiEndpoint) || this._servicePath; this._providedCustomServicePath = !!((_opts9 = opts) !== null && _opts9 !== void 0 && _opts9.servicePath || (_opts0 = opts) !== null && _opts0 !== void 0 && _opts0.apiEndpoint); var port = ((_opts1 = opts) === null || _opts1 === void 0 ? void 0 : _opts1.port) || staticMembers.port; var clientConfig = (_opts$clientConfig = (_opts10 = opts) === null || _opts10 === void 0 ? void 0 : _opts10.clientConfig) !== null && _opts$clientConfig !== void 0 ? _opts$clientConfig : {}; var fallback = (_opts$fallback = (_opts11 = opts) === null || _opts11 === void 0 ? void 0 : _opts11.fallback) !== null && _opts$fallback !== void 0 ? _opts$fallback : typeof window !== 'undefined' && typeof ((_window = window) === null || _window === void 0 ? void 0 : _window.fetch) === 'function'; opts = Object.assign({ servicePath: servicePath, port: port, clientConfig: clientConfig, fallback: fallback }, opts); // Request numeric enum values if REST transport is used. opts.numericEnums = true; // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. if (servicePath !== this._servicePath && !('scopes' in opts)) { opts['scopes'] = staticMembers.scopes; } // Load google-gax module synchronously if needed if (!gaxInstance) { gaxInstance = gax; } // Choose either gRPC or proto-over-HTTP implementation of google-gax. this._gaxModule = opts.fallback ? gaxInstance.fallback : gaxInstance; // Create a `gaxGrpc` object, with any grpc-specific options sent to the client. this._gaxGrpc = new this._gaxModule.GrpcClient(opts); // Save options to use in initialize() method. this._opts = opts; // Save the auth object to the client, for use by other methods. this.auth = this._gaxGrpc.auth; // Set useJWTAccessWithScope on the auth object. this.auth.useJWTAccessWithScope = true; // Set defaultServicePath on the auth object. this.auth.defaultServicePath = this._servicePath; // Set the default scopes in auth client if needed. if (servicePath === this._servicePath) { this.auth.defaultScopes = staticMembers.scopes; } this.locationsClient = new this._gaxModule.LocationsClient(this._gaxGrpc, opts); // Add ESM headers var isEsm = false; var isEsmString = isEsm ? '-esm' : '-cjs'; // Determine the client header string. var clientHeader = ["gax/".concat(this._gaxModule.version), "gapic/".concat(version)]; if ((typeof process === "undefined" ? "undefined" : _typeof(process)) === 'object' && 'versions' in process) { clientHeader.push("gl-node/{process.versions.node}".concat(isEsmString)); } else { clientHeader.push("gl-web/".concat(this._gaxModule.version)); } if (!opts.fallback) { clientHeader.push("grpc/".concat(this._gaxGrpc.grpcVersion)); } else if (opts.fallback === 'rest') { clientHeader.push("rest/".concat(this._gaxGrpc.grpcVersion)); } if (opts.libName && opts.libVersion) { clientHeader.push("".concat(opts.libName, "/").concat(opts.libVersion)); } // Load the applicable protos. this._protos = this._gaxGrpc.loadProtoJSON(jsonProtos); // This API contains "path templates"; forward-slash-separated // identifiers to uniquely identify resources within the API. // Create useful helper objects for these. this.pathTemplates = { locationPathTemplate: new this._gaxModule.PathTemplate('projects/{project}/locations/{location}'), projectPathTemplate: new this._gaxModule.PathTemplate('projects/{project}'), queuePathTemplate: new this._gaxModule.PathTemplate('projects/{project}/locations/{location}/queues/{queue}'), taskPathTemplate: new this._gaxModule.PathTemplate('projects/{project}/locations/{location}/queues/{queue}/tasks/{task}') }; // Some of the methods on this service return "paged" results, // (e.g. 50 results at a time, with tokens to get subsequent // pages). Denote the keys used for pagination and results. this.descriptors.page = { listQueues: new this._gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'queues'), listTasks: new this._gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'tasks') }; // Put together the default options sent with requests. this._defaults = this._gaxGrpc.constructSettings('google.cloud.tasks.v2beta2.CloudTasks', gapicConfig, opts.clientConfig || {}, { 'x-goog-api-client': clientHeader.join(' ') }); // Set up a dictionary of "inner API calls"; the core implementation // of calling the API is handled in `google-gax`, with this code // merely providing the destination and request information. this.innerApiCalls = {}; // Add a warn function to the client constructor so it can be easily tested. this.warn = this._gaxModule.warn; } /** * Initialize the client. * Performs asynchronous operations (such as authentication) and prepares the client. * This function will be called automatically when any class method is called for the * first time, but if you need to initialize it before calling an actual method, * feel free to call initialize() directly. * * You can await on this method if you want to make sure the client is initialized. * * @returns {Promise} A promise that resolves to an authenticated service stub. */ return _createClass(CloudTasksClient, [{ key: "initialize", value: function initialize() { var _this = this; // If the client stub promise is already initialized, return immediately. if (this.cloudTasksStub) { return this.cloudTasksStub; } // Put together the "service stub" for // google.cloud.tasks.v2beta2.CloudTasks. this.cloudTasksStub = this._gaxGrpc.createStub(this._opts.fallback ? this._protos.lookupService('google.cloud.tasks.v2beta2.CloudTasks') : // eslint-disable-next-line @typescript-eslint/no-explicit-any this._protos.google.cloud.tasks.v2beta2.CloudTasks, this._opts, this._providedCustomServicePath); // Iterate over each of the methods that the service provides // and create an API call method for each. var cloudTasksStubMethods = ['listQueues', 'getQueue', 'createQueue', 'updateQueue', 'deleteQueue', 'purgeQueue', 'pauseQueue', 'resumeQueue', 'uploadQueueYaml', 'getIamPolicy', 'setIamPolicy', 'testIamPermissions', 'listTasks', 'getTask', 'createTask', 'deleteTask', 'leaseTasks', 'acknowledgeTask', 'renewLease', 'cancelLease', 'runTask']; var _loop = function _loop() { var methodName = _cloudTasksStubMethod[_i]; var callPromise = _this.cloudTasksStub.then(function (stub) { return function () { if (_this._terminated) { return Promise.reject('The client has already been closed.'); } var func = stub[methodName]; for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } return func.apply(stub, args); }; }, function (err) { return function () { throw err; }; }); var descriptor = _this.descriptors.page[methodName] || undefined; var apiCall = _this._gaxModule.createApiCall(callPromise, _this._defaults[methodName], descriptor, _this._opts.fallback); _this.innerApiCalls[methodName] = apiCall; }; for (var _i = 0, _cloudTasksStubMethod = cloudTasksStubMethods; _i < _cloudTasksStubMethod.length; _i++) { _loop(); } return this.cloudTasksStub; } /** * The DNS address for this API service. * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ }, { key: "apiEndpoint", get: /** * The DNS address for this API service. * @returns {string} The DNS address for this service. */ function get() { return this._servicePath; } }, { key: "universeDomain", get: function get() { return this._universeDomain; } /** * The port for this API service. * @returns {number} The default port for this service. */ }, { key: "getProjectId", value: /** * Return the project ID used by this class. * @returns {Promise} A promise that resolves to string containing the project ID. */ function getProjectId(callback) { if (callback) { this.auth.getProjectId(callback); return; } return this.auth.getProjectId(); } // ------------------- // -- Service calls -- // ------------------- /** * Gets a queue. * * @param {Object} request * The request object that will be sent. * @param {string} request.name * Required. The resource name of the queue. For example: * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID` * @param {google.protobuf.FieldMask} [request.readMask] * Optional. Read mask is used for a more granular control over what the API * returns. If the mask is not present all fields will be returned except * [Queue.stats]. [Queue.stats] will be returned only if it was explicitly * specified in the mask. * @param {object} [options] * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. * @returns {Promise} - The promise which resolves to an array. * The first element of the array is an object representing {@link protos.google.cloud.tasks.v2beta2.Queue|Queue}. * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } * for more details and examples. * @example <caption>include:samples/generated/v2beta2/cloud_tasks.get_queue.js</caption> * region_tag:cloudtasks_v2beta2_generated_CloudTasks_GetQueue_async */ }, { key: "getQueue", value: function getQueue(request, optionsOrCallback, callback) { var _request$name, _this2 = this, _this$innerApiCalls$g; request = request || {}; var options; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; } else { options = optionsOrCallback; } options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ 'name': (_request$name = request.name) !== null && _request$name !== void 0 ? _request$name : '' }); this.initialize()["catch"](function (err) { throw err; }); this._log.info('getQueue request %j', request); var wrappedCallback = callback ? function (error, response, options, rawResponse) { _this2._log.info('getQueue response %j', response); callback(error, response, options, rawResponse); } : undefined; return (_this$innerApiCalls$g = this.innerApiCalls.getQueue(request, options, wrappedCallback)) === null || _this$innerApiCalls$g === void 0 ? void 0 : _this$innerApiCalls$g.then(function (_ref3) { var _ref4 = _slicedToArray(_ref3, 3), response = _ref4[0], options = _ref4[1], rawResponse = _ref4[2]; _this2._log.info('getQueue response %j', response); return [response, options, rawResponse]; })["catch"](function (error) { if (error && 'statusDetails' in error && error.statusDetails instanceof Array) { var _protos = _this2._gaxModule.protobuf.Root.fromJSON(jsonProtos); error.statusDetails = (0, _googleGax.decodeAnyProtosInArray)(error.statusDetails, _protos); } throw error; }); } /** * Creates a queue. * * Queues created with this method allow tasks to live for a maximum of 31 * days. After a task is 31 days old, the task will be deleted regardless of * whether it was dispatched or not. * * WARNING: Using this method may have unintended side effects if you are * using an App Engine `queue.yaml` or `queue.xml` file to manage your queues. * Read * [Overview of Queue Management and * queue.yaml](https://cloud.google.com/tasks/docs/queue-yaml) before using * this method. * * @param {Object} request * The request object that will be sent. * @param {string} request.parent * Required. The location name in which the queue will be created. * For example: `projects/PROJECT_ID/locations/LOCATION_ID` * * The list of allowed locations can be obtained by calling Cloud * Tasks' implementation of * {@link protos.google.cloud.location.Locations.ListLocations|ListLocations}. * @param {google.cloud.tasks.v2beta2.Queue} request.queue * Required. The queue to create. * * {@link protos.google.cloud.tasks.v2beta2.Queue.name|Queue's name} cannot be the same as * an existing queue. * @param {object} [options] * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. * @returns {Promise} - The promise which resolves to an array. * The first element of the array is an object representing {@link protos.google.cloud.tasks.v2beta2.Queue|Queue}. * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } * for more details and examples. * @example <caption>include:samples/generated/v2beta2/cloud_tasks.create_queue.js</caption> * region_tag:cloudtasks_v2beta2_generated_CloudTasks_CreateQueue_async */ }, { key: "createQueue", value: function createQueue(request, optionsOrCallback, callback) { var _request$parent, _this3 = this, _this$innerApiCalls$c; request = request || {}; var options; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; } else { options = optionsOrCallback; } options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ 'parent': (_request$parent = request.parent) !== null && _request$parent !== void 0 ? _request$parent : '' }); this.initialize()["catch"](function (err) { throw err; }); this._log.info('createQueue request %j', request); var wrappedCallback = callback ? function (error, response, options, rawResponse) { _this3._log.info('createQueue response %j', response); callback(error, response, options, rawResponse); } : undefined; return (_this$innerApiCalls$c = this.innerApiCalls.createQueue(request, options, wrappedCallback)) === null || _this$innerApiCalls$c === void 0 ? void 0 : _this$innerApiCalls$c.then(function (_ref5) { var _ref6 = _slicedToArray(_ref5, 3), response = _ref6[0], options = _ref6[1], rawResponse = _ref6[2]; _this3._log.info('createQueue response %j', response); return [response, options, rawResponse]; })["catch"](function (error) { if (error && 'statusDetails' in error && error.statusDetails instanceof Array) { var _protos2 = _this3._gaxModule.protobuf.Root.fromJSON(jsonProtos); error.statusDetails = (0, _googleGax.decodeAnyProtosInArray)(error.statusDetails, _protos2); } throw error; }); } /** * Updates a queue. * * This method creates the queue if it does not exist and updates * the queue if it does exist. * * Queues created with this method allow tasks to live for a maximum of 31 * days. After a task is 31 days old, the task will be deleted regardless of * whether it was dispatched or not. * * WARNING: Using this method may have unintended side effects if you are * using an App Engine `queue.yaml` or `queue.xml` file to manage your queues. * Read * [Overview of Queue Management and * queue.yaml](https://cloud.google.com/tasks/docs/queue-yaml) before using * this method. * * @param {Object} request * The request object that will be sent. * @param {google.cloud.tasks.v2beta2.Queue} request.queue * Required. The queue to create or update. * * The queue's {@link protos.google.cloud.tasks.v2beta2.Queue.name|name} must be * specified. * * Output only fields cannot be modified using UpdateQueue. * Any value specified for an output only field will be ignored. * The queue's {@link protos.google.cloud.tasks.v2beta2.Queue.name|name} cannot be * changed. * @param {google.protobuf.FieldMask} request.updateMask * A mask used to specify which fields of the queue are being updated. * * If empty, then all fields will be updated. * @param {object} [options] * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. * @returns {Promise} - The promise which resolves to an array. * The first element of the array is an object representing {@link protos.google.cloud.tasks.v2beta2.Queue|Queue}. * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } * for more details and examples. * @example <caption>include:samples/generated/v2beta2/cloud_tasks.update_queue.js</caption> * region_tag:cloudtasks_v2beta2_generated_CloudTasks_UpdateQueue_async */ }, { key: "updateQueue", value: function updateQueue(request, optionsOrCallback, callback) { var _name, _this4 = this, _this$innerApiCalls$u; request = request || {}; var options; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; } else { options = optionsOrCallback; } options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ 'queue.name': (_name = request.queue.name) !== null && _name !== void 0 ? _name : '' }); this.initialize()["catch"](function (err) { throw err; }); this._log.info('updateQueue request %j', request); var wrappedCallback = callback ? function (error, response, options, rawResponse) { _this4._log.info('updateQueue response %j', response); callback(error, response, options, rawResponse); } : undefined; return (_this$innerApiCalls$u = this.innerApiCalls.updateQueue(request, options, wrappedCallback)) === null || _this$innerApiCalls$u === void 0 ? void 0 : _this$innerApiCalls$u.then(function (_ref7) { var _ref8 = _slicedToArray(_ref7, 3), response = _ref8[0], options = _ref8[1], rawResponse = _ref8[2]; _this4._log.info('updateQueue response %j', response); return [response, options, rawResponse]; })["catch"](function (error) { if (error && 'statusDetails' in error && error.statusDetails instanceof Array) { var _protos3 = _this4._gaxModule.protobuf.Root.fromJSON(jsonProtos); error.statusDetails = (0, _googleGax.decodeAnyProtosInArray)(error.statusDetails, _protos3); } throw error; }); } /** * Deletes a queue. * * This command will delete the queue even if it has tasks in it. * * Note: If you delete a queue, a queue with the same name can't be created * for 7 days. * * WARNING: Using this method may have unintended side effects if you are * using an App Engine `queue.yaml` or `queue.xml` file to manage your queues. * Read * [Overview of Queue Management and * queue.yaml](https://cloud.google.com/tasks/docs/queue-yaml) before using * this method. * * @param {Object} request * The request object that will be sent. * @param {string} request.name * Required. The queue name. For example: * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID` * @param {object} [options] * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. * @returns {Promise} - The promise which resolves to an array. * The first element of the array is an object representing {@link protos.google.protobuf.Empty|Empty}. * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } * for more details and examples. * @example <caption>include:samples/generated/v2beta2/cloud_tasks.delete_queue.js</caption> * region_tag:cloudtasks_v2beta2_generated_CloudTasks_DeleteQueue_async */ }, { key: "deleteQueue", value: function deleteQueue(request, optionsOrCallback, callback) { var _request$name2, _this5 = this, _this$innerApiCalls$d; request = request || {}; var options; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; } else { options = optionsOrCallback; } options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ 'name': (_request$name2 = request.name) !== null && _request$name2 !== void 0 ? _request$name2 : '' }); this.initialize()["catch"](function (err) { throw err; }); this._log.info('deleteQueue request %j', request); var wrappedCallback = callback ? function (error, response, options, rawResponse) { _this5._log.info('deleteQueue response %j', response); callback(error, response, options, rawResponse); } : undefined; return (_this$innerApiCalls$d = this.innerApiCalls.deleteQueue(request, options, wrappedCallback)) === null || _this$innerApiCalls$d === void 0 ? void 0 : _this$innerApiCalls$d.then(function (_ref9) { var _ref0 = _slicedToArray(_ref9, 3), response = _ref0[0], options = _ref0[1], rawResponse = _ref0[2]; _this5._log.info('deleteQueue response %j', response); return [response, options, rawResponse]; })["catch"](function (error) { if (error && 'statusDetails' in error && error.statusDetails instanceof Array) { var _protos4 = _this5._gaxModule.protobuf.Root.fromJSON(jsonProtos); error.statusDetails = (0, _googleGax.decodeAnyProtosInArray)(error.statusDetails, _protos4); } throw error; }); } /** * Purges a queue by deleting all of its tasks. * * All tasks created before this method is called are permanently deleted. * * Purge operations can take up to one minute to take effect. Tasks * might be dispatched before the purge takes effect. A purge is irreversible. * * @param {Object} request * The request object that will be sent. * @param {string} request.name * Required. The queue name. For example: * `projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID` * @param {object} [options] * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. * @returns {Promise} - The promise which resolves to an array. * The first element of the array is an object representing {@link protos.google.cloud.tasks.v2beta2.Queue|Queue}. * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } * for more details and examples. * @example <caption>include:samples/generated/v2beta2/cloud_tasks.purge_queue.js</caption> * region_tag:cloudtasks_v2beta2_generated_CloudTasks_PurgeQueue_async */ }, { key: "purgeQueue", value: function purgeQueue(request, optionsOrCallback, callback) { var _request$name3, _this6 = this, _this$innerApiCalls$p; request = request || {}; var options; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; } else { options = optionsOrCallback; } options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ 'name': (_request$name3 = request.name) !== null && _request$name3 !== void 0 ? _request$name3 : '' }); this.initialize()["catch"](function (err) { throw err; }); this._log.info('purgeQueue request %j', request); var wrappedCallback = callback ? function (error, response, options, rawResponse) { _this6._log.info('purgeQueue response %j', response); callback(error, response, options, rawResponse); } : undefined; return (_this$innerApiCalls$p = this.innerApiCalls.purgeQueue(request, options, wrappedCallback)) === null || _this$innerApiCalls$p === void 0 ? void 0 : _this$innerApiCalls$p.then(function (_ref1) { var _ref10 = _slicedToArray(_ref1, 3), response = _ref10[0], options = _ref10[1], rawResponse = _ref10[2]; _this6._log.info('purgeQueue response %j', response); return [response, options, rawResponse]; })["catch"](function (error) { if (error && 'statusDetails' in error && error.statusDetails instanceof Array) { var _protos5 = _this6._gaxModule.protobuf.Root.fromJSON(jsonProtos); error.statusDetails = (0, _googleGax.decodeAnyProtosInArray)(error.statusDetails, _protos5); } throw error; }); } /** * Pauses the queue. * * If a queue is paused then the system will stop dispatching tasks * until the queue is resumed via * {@link protos.google.cloud.tasks.v2beta2.CloudTasks.ResumeQueue|ResumeQueue}. Tasks can * still be added when the queue is paused. A queue is paused if its * {@link protos.google.cloud.tasks.v2beta2.Queue.state|state} is * {@link protos.google.cloud.tasks.v2beta2.Queue.State.PAUSED|PAUSED}. * * @param {Object} request * The request object that will be sent. * @param {string} request.name * Required. The queue name. For example: * `projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID` * @param {object} [options] * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. * @returns {Promise} - The promise which resolves to an array. * The first element of the array is an object representing {@link protos.google.cloud.tasks.v2beta2.Queue|Queue}. * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } * for more details and examples. * @example <caption>include:samples/generated/v2beta2/cloud_tasks.pause_queue.js</caption> * region_tag:cloudtasks_v2beta2_generated_CloudTasks_PauseQueue_async */ }, { key: "pauseQueue", value: function pauseQueue(request, optionsOrCallback, callback) { var _request$name4, _this7 = this, _this$innerApiCalls$p2; request = request || {}; var options; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; } else { options = optionsOrCallback; } options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ 'name': (_request$name4 = request.name) !== null && _request$name4 !== void 0 ? _request$name4 : '' }); this.initialize()["catch"](function (err) { throw err; }); this._log.info('pauseQueue request %j', request); var wrappedCallback = callback ? function (error, response, options, rawResponse) { _this7._log.info('pauseQueue response %j', response); callback(error, response, options, rawResponse); } : undefined; return (_this$innerApiCalls$p2 = this.innerApiCalls.pauseQueue(request, options, wrappedCallback)) === null || _this$innerApiCalls$p2 === void 0 ? void 0 : _this$innerApiCalls$p2.then(function (_ref11) { var _ref12 = _slicedToArray(_ref11, 3), response = _ref12[0], options = _ref12[1], rawResponse = _ref12[2]; _this7._log.info('pauseQueue response %j', response); return [response, options, rawResponse]; })["catch"](function (error) { if (error && 'statusDetails' in error && error.statusDetails instanceof Array) { var _protos6 = _this7._gaxModule.protobuf.Root.fromJSON(jsonProtos); error.statusDetails = (0, _googleGax.decodeAnyProtosInArray)(error.statusDetails, _protos6); } throw error; }); } /** * Resume a queue. * * This method resumes a queue after it has been * {@link protos.google.cloud.tasks.v2beta2.Queue.State.PAUSED|PAUSED} or * {@link protos.google.cloud.tasks.v2beta2.Queue.State.DISABLED|DISABLED}. The state of a * queue is stored in the queue's * {@link protos.google.cloud.tasks.v2beta2.Queue.state|state}; after calling this method * it will be set to * {@link protos.google.cloud.tasks.v2beta2.Queue.State.RUNNING|RUNNING}. * * WARNING: Resuming many high-QPS queues at the same time can * lead to target overloading. If you are resuming high-QPS * queues, follow the 500/50/5 pattern described in * [Managing Cloud Tasks Scaling * Risks](https://cloud.google.com/tasks/docs/manage-cloud-task-scaling). * * @param {Object} request * The request object that will be sent. * @param {string} request.name * Required. The queue name. For example: * `projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID` * @param {object} [options] * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. * @returns {Promise} - The promise which resolves to an array. * The first element of the array is an object representing {@link protos.google.cloud.tasks.v2beta2.Queue|Queue}. * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } * for more details and examples. * @example <caption>include:samples/generated/v2beta2/cloud_tasks.resume_queue.js</caption> * region_tag:cloudtasks_v2beta2_generated_CloudTasks_ResumeQueue_async */ }, { key: "resumeQueue", value: function resumeQueue(request, optionsOrCallback, callback) { var _request$name5, _this8 = this, _this$innerApiCalls$r; request = request || {}; var options; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; } else { options = optionsOrCallback; } options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ 'name': (_request$name5 = request.name) !== null && _request$name5 !== void 0 ? _request$name5 : '' }); this.initialize()["catch"](function (err) { throw err; }); this._log.info('resumeQueue request %j', request); var wrappedCallback = callback ? function (error, response, options, rawResponse) { _this8._log.info('resumeQueue response %j', response); callback(error, response, options, rawResponse); } : undefined; return (_this$innerApiCalls$r = this.innerApiCalls.resumeQueue(request, options, wrappedCallback)) === null || _this$innerApiCalls$r === void 0 ? void 0 : _this$innerApiCalls$r.then(function (_ref13) { var _ref14 = _slicedToArray(_ref13, 3), response = _ref14[0], options = _ref14[1], rawResponse = _ref14[2]; _this8._log.info('resumeQueue response %j', response); return [response, options, rawResponse]; })["catch"](function (error) { if (error && 'statusDetails' in error && error.statusDetails instanceof Array) { var _protos7 = _this8._gaxModule.protobuf.Root.fromJSON(jsonProtos); error.statusDetails = (0, _googleGax.decodeAnyProtosInArray)(error.statusDetails, _protos7); } throw error; }); } /** * Update queue list by uploading a queue.yaml file. * * The queue.yaml file is supplied in the request body as a YAML encoded * string. This method was added to support gcloud clients versions before * 322.0.0. New clients should use CreateQueue instead of this method. * * @param {Object} request * The request object that will be sent. * @param {string} request.appId * Required. The App ID is supplied as an HTTP parameter. Unlike internal * usage of App ID, it does not include a region prefix. Rather, the App ID * represents the Project ID against which to make the request. * @param {google.api.HttpBody} request.httpBody * The http body contains the queue.yaml file which used to update queue lists * @param {object} [options] * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. * @returns {Promise} - The promise which resolves to an array. * The first element of the array is an object representing {@link protos.google.protobuf.Empty|Empty}. * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } * for more details and examples. * @example <caption>include:samples/generated/v2beta2/cloud_tasks.upload_queue_yaml.js</caption> * region_tag:cloudtasks_v2beta2_generated_CloudTasks_UploadQueueYaml_async */ }, { key: "uploadQueueYaml", value: function uploadQueueYaml(request, optionsOrCallback, callback) { var _this9 = this, _this$innerApiCalls$u2; request = request || {}; var options; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; } else { options = optionsOrCallback; } options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; this.initialize()["catch"](function (err) { throw err; }); this._log.info('uploadQueueYaml request %j', request); var wrappedCallback = callback ? function (error, response, options, rawResponse) { _this9._log.info('uploadQueueYaml response %j', response); callback(error, response, options, rawResponse); } : undefined; return (_this$innerApiCalls$u2 = this.innerApiCalls.uploadQueueYaml(request, options, wrappedCallback)) === null || _this$innerApiCalls$u2 === void 0 ? void 0 : _this$innerApiCalls$u2.then(function (_ref15) { var _ref16 = _slicedToArray(_ref15, 3), response = _ref16[0], options = _ref16[1], rawResponse = _ref16[2]; _this9._log.info('uploadQueueYaml response %j', response); return [response, options, rawResponse]; })["catch"](function (error) { if (error && 'statusDetails' in error && error.statusDetails instanceof Array) { var _protos8 = _this9._gaxModule.protobuf.Root.fromJSON(jsonProtos); error.statusDetails = (0, _googleGax.decodeAnyProtosInArray)(error.statusDetails, _protos8); } throw error; }); } /** * Gets the access control policy for a * {@link protos.google.cloud.tasks.v2beta2.Queue|Queue}. Returns an empty policy if the * resource exists and does not have a policy set. * * Authorization requires the following * [Google IAM](https://cloud.google.com/iam) permission on the specified * resource parent: * * * `cloudtasks.queues.getIamPolicy` * * @param {Object} request * The request object that will be sent. * @param {string} request.resource * REQUIRED: The resource for which the policy is being requested. * See the operation documentation for the appropriate value for this field. * @param {google.iam.v1.GetPolicyOptions} request.options * OPTIONAL: A `GetPolicyOptions` object for specifying options to * `GetIamPolicy`. * @param {object} [options] * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. * @returns {Promise} - The promise which resolves to an array. * The first element of the array is an object representing {@link protos.google.iam.v1.Policy|Policy}. * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } * for more details and examples. * @example <caption>include:samples/generated/v2beta2/cloud_tasks.get_iam_policy.js</caption> * region_tag:cloudtasks_v2beta2_generated_CloudTasks_GetIamPolicy_async */ }, { key: "getIamPolicy", value: function getIamPolicy(request, optionsOrCallback, callback) { var _request$resource, _this0 = this, _this$innerApiCalls$g2; request = request || {}; var options; if (typeof optionsOrCallback === 'function' && callback === undefin