v2beta2/cloud_tasks_client.js

"use strict";
// Copyright 2019 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. **
Object.defineProperty(exports, "__esModule", { value: true });
const gax = require("google-gax");
const path = require("path");
const gapicConfig = require("./cloud_tasks_client_config.json");
const version = require('../../../package.json').version;
/**
 *  Cloud Tasks allows developers to manage the execution of background
 *  work in their applications.
 * @class
 * @memberof v2beta2
 */
class CloudTasksClient {
    /**
     * Construct an instance of CloudTasksClient.
     *
     * @param {object} [options] - The configuration object. See the subsequent
     *   parameters for more details.
     * @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://developers.google.com/identity/protocols/application-default-credentials Application Default Credentials},
     *     your project ID will be detected automatically.
     * @param {function} [options.promise] - Custom promise module to use instead
     *     of native Promises.
     * @param {string} [options.apiEndpoint] - The domain name of the
     *     API remote host.
     */
    constructor(opts) {
        this._descriptors = { page: {}, stream: {}, longrunning: {} };
        this._terminated = false;
        // Ensure that options include the service address and port.
        const staticMembers = this.constructor;
        const servicePath = opts && opts.servicePath
            ? opts.servicePath
            : opts && opts.apiEndpoint
                ? opts.apiEndpoint
                : staticMembers.servicePath;
        const port = opts && opts.port ? opts.port : staticMembers.port;
        if (!opts) {
            opts = { servicePath, port };
        }
        opts.servicePath = opts.servicePath || servicePath;
        opts.port = opts.port || port;
        opts.clientConfig = opts.clientConfig || {};
        const isBrowser = typeof window !== 'undefined';
        if (isBrowser) {
            opts.fallback = true;
        }
        // If we are in browser, we are already using fallback because of the
        // "browser" field in package.json.
        // But if we were explicitly requested to use fallback, let's do it now.
        const gaxModule = !isBrowser && opts.fallback ? gax.fallback : gax;
        // Create a `gaxGrpc` object, with any grpc-specific options
        // sent to the client.
        opts.scopes = this.constructor.scopes;
        const gaxGrpc = new gaxModule.GrpcClient(opts);
        // Save the auth object to the client, for use by other methods.
        this.auth = gaxGrpc.auth;
        // Determine the client header string.
        const clientHeader = [`gax/${gaxModule.version}`, `gapic/${version}`];
        if (typeof process !== 'undefined' && 'versions' in process) {
            clientHeader.push(`gl-node/${process.versions.node}`);
        }
        else {
            clientHeader.push(`gl-web/${gaxModule.version}`);
        }
        if (!opts.fallback) {
            clientHeader.push(`grpc/${gaxGrpc.grpcVersion}`);
        }
        if (opts.libName && opts.libVersion) {
            clientHeader.push(`${opts.libName}/${opts.libVersion}`);
        }
        // Load the applicable protos.
        // For Node.js, pass the path to JSON proto file.
        // For browsers, pass the JSON content.
        const nodejsProtoPath = path.join(__dirname, '..', '..', 'protos', 'protos.json');
        const protos = gaxGrpc.loadProto(opts.fallback ? require('../../protos/protos.json') : nodejsProtoPath);
        // This API contains "path templates"; forward-slash-separated
        // identifiers to uniquely identify resources within the API.
        // Create useful helper objects for these.
        this._pathTemplates = {
            projectPathTemplate: new gaxModule.PathTemplate('projects/{project}'),
            locationPathTemplate: new gaxModule.PathTemplate('projects/{project}/locations/{location}'),
            queuePathTemplate: new gaxModule.PathTemplate('projects/{project}/locations/{location}/queues/{queue}'),
            taskPathTemplate: new 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 gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'queues'),
            listTasks: new gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'tasks'),
        };
        // Put together the default options sent with requests.
        const defaults = 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 = {};
        // Put together the "service stub" for
        // google.cloud.tasks.v2beta2.CloudTasks.
        this.cloudTasksStub = gaxGrpc.createStub(opts.fallback
            ? protos.lookupService('google.cloud.tasks.v2beta2.CloudTasks')
            : // tslint:disable-next-line no-any
                protos.google.cloud.tasks.v2beta2.CloudTasks, opts);
        // Iterate over each of the methods that the service provides
        // and create an API call method for each.
        const cloudTasksStubMethods = [
            'listQueues',
            'getQueue',
            'createQueue',
            'updateQueue',
            'deleteQueue',
            'purgeQueue',
            'pauseQueue',
            'resumeQueue',
            'getIamPolicy',
            'setIamPolicy',
            'testIamPermissions',
            'listTasks',
            'getTask',
            'createTask',
            'deleteTask',
            'leaseTasks',
            'acknowledgeTask',
            'renewLease',
            'cancelLease',
            'runTask',
        ];
        for (const methodName of cloudTasksStubMethods) {
            const innerCallPromise = this.cloudTasksStub.then(stub => (...args) => {
                if (this._terminated) {
                    return Promise.reject('The client has already been closed.');
                }
                return stub[methodName].apply(stub, args);
            }, (err) => () => {
                throw err;
            });
            const apiCall = gaxModule.createApiCall(innerCallPromise, defaults[methodName], this._descriptors.page[methodName] ||
                this._descriptors.stream[methodName] ||
                this._descriptors.longrunning[methodName]);
            this._innerApiCalls[methodName] = (argument, callOptions, callback) => {
                return apiCall(argument, callOptions, callback);
            };
        }
    }
    /**
     * The DNS address for this API service.
     */
    static get servicePath() {
        return 'cloudtasks.googleapis.com';
    }
    /**
     * The DNS address for this API service - same as servicePath(),
     * exists for compatibility reasons.
     */
    static get apiEndpoint() {
        return 'cloudtasks.googleapis.com';
    }
    /**
     * The port for this API service.
     */
    static get port() {
        return 443;
    }
    /**
     * The scopes needed to make gRPC calls for every method defined
     * in this service.
     */
    static get scopes() {
        return ['https://www.googleapis.com/auth/cloud-platform'];
    }
    /**
     * Return the project ID used by this class.
     * @param {function(Error, string)} callback - the callback to
     *   be called with the current project Id.
     */
    getProjectId(callback) {
        if (callback) {
            this.auth.getProjectId(callback);
            return;
        }
        return this.auth.getProjectId();
    }
    /**
     * 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 {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 [Queue]{@link google.cloud.tasks.v2beta2.Queue}.
     *   The promise has a method named "cancel" which cancels the ongoing API call.
     */
    getQueue(request, optionsOrCallback, callback) {
        request = request || {};
        let 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'] = gax.routingHeader.fromParams({
            name: request.name || '',
        });
        return this._innerApiCalls.getQueue(request, options, callback);
    }
    /**
     * 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
     *   [ListLocations][google.cloud.location.Locations.ListLocations].
     * @param {google.cloud.tasks.v2beta2.Queue} request.queue
     *   Required. The queue to create.
     *
     *   [Queue's name][google.cloud.tasks.v2beta2.Queue.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 [Queue]{@link google.cloud.tasks.v2beta2.Queue}.
     *   The promise has a method named "cancel" which cancels the ongoing API call.
     */
    createQueue(request, optionsOrCallback, callback) {
        request = request || {};
        let 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'] = gax.routingHeader.fromParams({
            parent: request.parent || '',
        });
        return this._innerApiCalls.createQueue(request, options, callback);
    }
    /**
     * 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 [name][google.cloud.tasks.v2beta2.Queue.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 [name][google.cloud.tasks.v2beta2.Queue.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 [Queue]{@link google.cloud.tasks.v2beta2.Queue}.
     *   The promise has a method named "cancel" which cancels the ongoing API call.
     */
    updateQueue(request, optionsOrCallback, callback) {
        request = request || {};
        let 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'] = gax.routingHeader.fromParams({
            'queue.name': request.queue.name || '',
        });
        return this._innerApiCalls.updateQueue(request, options, callback);
    }
    /**
     * 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 [Empty]{@link google.protobuf.Empty}.
     *   The promise has a method named "cancel" which cancels the ongoing API call.
     */
    deleteQueue(request, optionsOrCallback, callback) {
        request = request || {};
        let 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'] = gax.routingHeader.fromParams({
            name: request.name || '',
        });
        return this._innerApiCalls.deleteQueue(request, options, callback);
    }
    /**
     * 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 [Queue]{@link google.cloud.tasks.v2beta2.Queue}.
     *   The promise has a method named "cancel" which cancels the ongoing API call.
     */
    purgeQueue(request, optionsOrCallback, callback) {
        request = request || {};
        let 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'] = gax.routingHeader.fromParams({
            name: request.name || '',
        });
        return this._innerApiCalls.purgeQueue(request, options, callback);
    }
    /**
     * Pauses the queue.
     *
     * If a queue is paused then the system will stop dispatching tasks
     * until the queue is resumed via
     * [ResumeQueue][google.cloud.tasks.v2beta2.CloudTasks.ResumeQueue]. Tasks can still be added
     * when the queue is paused. A queue is paused if its
     * [state][google.cloud.tasks.v2beta2.Queue.state] is [PAUSED][google.cloud.tasks.v2beta2.Queue.State.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 [Queue]{@link google.cloud.tasks.v2beta2.Queue}.
     *   The promise has a method named "cancel" which cancels the ongoing API call.
     */
    pauseQueue(request, optionsOrCallback, callback) {
        request = request || {};
        let 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'] = gax.routingHeader.fromParams({
            name: request.name || '',
        });
        return this._innerApiCalls.pauseQueue(request, options, callback);
    }
    /**
     * Resume a queue.
     *
     * This method resumes a queue after it has been
     * [PAUSED][google.cloud.tasks.v2beta2.Queue.State.PAUSED] or
     * [DISABLED][google.cloud.tasks.v2beta2.Queue.State.DISABLED]. The state of a queue is stored
     * in the queue's [state][google.cloud.tasks.v2beta2.Queue.state]; after calling this method it
     * will be set to [RUNNING][google.cloud.tasks.v2beta2.Queue.State.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 [Queue]{@link google.cloud.tasks.v2beta2.Queue}.
     *   The promise has a method named "cancel" which cancels the ongoing API call.
     */
    resumeQueue(request, optionsOrCallback, callback) {
        request = request || {};
        let 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'] = gax.routingHeader.fromParams({
            name: request.name || '',
        });
        return this._innerApiCalls.resumeQueue(request, options, callback);
    }
    /**
     * Gets the access control policy for a [Queue][google.cloud.tasks.v2beta2.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 {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 [Policy]{@link google.iam.v1.Policy}.
     *   The promise has a method named "cancel" which cancels the ongoing API call.
     */
    getIamPolicy(request, optionsOrCallback, callback) {
        request = request || {};
        let 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'] = gax.routingHeader.fromParams({
            resource: request.resource || '',
        });
        return this._innerApiCalls.getIamPolicy(request, options, callback);
    }
    /**
     * Sets the access control policy for a [Queue][google.cloud.tasks.v2beta2.Queue]. Replaces any existing
     * policy.
     *
     * Note: The Cloud Console does not check queue-level IAM permissions yet.
     * Project-level permissions are required to use the Cloud Console.
     *
     * Authorization requires the following
     * [Google IAM](https://cloud.google.com/iam) permission on the specified
     * resource parent:
     *
     * * `cloudtasks.queues.setIamPolicy`
     *
     * @param {Object} request
     *   The request object that will be sent.
     * @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 [Policy]{@link google.iam.v1.Policy}.
     *   The promise has a method named "cancel" which cancels the ongoing API call.
     */
    setIamPolicy(request, optionsOrCallback, callback) {
        request = request || {};
        let 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'] = gax.routingHeader.fromParams({
            resource: request.resource || '',
        });
        return this._innerApiCalls.setIamPolicy(request, options, callback);
    }
    /**
     * Returns permissions that a caller has on a [Queue][google.cloud.tasks.v2beta2.Queue].
     * If the resource does not exist, this will return an empty set of
     * permissions, not a [NOT_FOUND][google.rpc.Code.NOT_FOUND] error.
     *
     * Note: This operation is designed to be used for building permission-aware
     * UIs and command-line tools, not for authorization checking. This operation
     * may "fail open" without warning.
     *
     * @param {Object} request
     *   The request object that will be sent.
     * @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 [TestIamPermissionsResponse]{@link google.iam.v1.TestIamPermissionsResponse}.
     *   The promise has a method named "cancel" which cancels the ongoing API call.
     */
    testIamPermissions(request, optionsOrCallback, callback) {
        request = request || {};
        let 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'] = gax.routingHeader.fromParams({
            resource: request.resource || '',
        });
        return this._innerApiCalls.testIamPermissions(request, options, callback);
    }
    /**
     * Gets a task.
     *
     * @param {Object} request
     *   The request object that will be sent.
     * @param {string} request.name
     *   Required. The task name. For example:
     *   `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`
     * @param {google.cloud.tasks.v2beta2.Task.View} request.responseView
     *   The response_view specifies which subset of the [Task][google.cloud.tasks.v2beta2.Task] will be
     *   returned.
     *
     *   By default response_view is [BASIC][google.cloud.tasks.v2beta2.Task.View.BASIC]; not all
     *   information is retrieved by default because some data, such as
     *   payloads, might be desirable to return only when needed because
     *   of its large size or because of the sensitivity of data that it
     *   contains.
     *
     *   Authorization for [FULL][google.cloud.tasks.v2beta2.Task.View.FULL] requires
     *   `cloudtasks.tasks.fullView` [Google IAM](https://cloud.google.com/iam/)
     *   permission on the [Task][google.cloud.tasks.v2beta2.Task] resource.
     * @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 [Task]{@link google.cloud.tasks.v2beta2.Task}.
     *   The promise has a method named "cancel" which cancels the ongoing API call.
     */
    getTask(request, optionsOrCallback, callback) {
        request = request || {};
        let 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'] = gax.routingHeader.fromParams({
            name: request.name || '',
        });
        return this._innerApiCalls.getTask(request, options, callback);
    }
    /**
     * Creates a task and adds it to a queue.
     *
     * Tasks cannot be updated after creation; there is no UpdateTask command.
     *
     * * For [App Engine queues][google.cloud.tasks.v2beta2.AppEngineHttpTarget], the maximum task size is
     *   100KB.
     * * For [pull queues][google.cloud.tasks.v2beta2.PullTarget], the maximum task size is 1MB.
     *
     * @param {Object} request
     *   The request object that will be sent.
     * @param {string} request.parent
     *   Required. The queue name. For example:
     *   `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`
     *
     *   The queue must already exist.
     * @param {google.cloud.tasks.v2beta2.Task} request.task
     *   Required. The task to add.
     *
     *   Task names have the following format:
     *   `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`.
     *   The user can optionally specify a task [name][google.cloud.tasks.v2beta2.Task.name]. If a
     *   name is not specified then the system will generate a random
     *   unique task id, which will be set in the task returned in the
     *   [response][google.cloud.tasks.v2beta2.Task.name].
     *
     *   If [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] is not set or is in the
     *   past then Cloud Tasks will set it to the current time.
     *
     *   Task De-duplication:
     *
     *   Explicitly specifying a task ID enables task de-duplication.  If
     *   a task's ID is identical to that of an existing task or a task
     *   that was deleted or completed recently then the call will fail
     *   with [ALREADY_EXISTS][google.rpc.Code.ALREADY_EXISTS].
     *   If the task's queue was created using Cloud Tasks, then another task with
     *   the same name can't be created for ~1hour after the original task was
     *   deleted or completed. If the task's queue was created using queue.yaml or
     *   queue.xml, then another task with the same name can't be created
     *   for ~9days after the original task was deleted or completed.
     *
     *   Because there is an extra lookup cost to identify duplicate task
     *   names, these [CreateTask][google.cloud.tasks.v2beta2.CloudTasks.CreateTask] calls have significantly
     *   increased latency. Using hashed strings for the task id or for
     *   the prefix of the task id is recommended. Choosing task ids that
     *   are sequential or have sequential prefixes, for example using a
     *   timestamp, causes an increase in latency and error rates in all
     *   task commands. The infrastructure relies on an approximately
     *   uniform distribution of task ids to store and serve tasks
     *   efficiently.
     * @param {google.cloud.tasks.v2beta2.Task.View} request.responseView
     *   The response_view specifies which subset of the [Task][google.cloud.tasks.v2beta2.Task] will be
     *   returned.
     *
     *   By default response_view is [BASIC][google.cloud.tasks.v2beta2.Task.View.BASIC]; not all
     *   information is retrieved by default because some data, such as
     *   payloads, might be desirable to return only when needed because
     *   of its large size or because of the sensitivity of data that it
     *   contains.
     *
     *   Authorization for [FULL][google.cloud.tasks.v2beta2.Task.View.FULL] requires
     *   `cloudtasks.tasks.fullView` [Google IAM](https://cloud.google.com/iam/)
     *   permission on the [Task][google.cloud.tasks.v2beta2.Task] resource.
     * @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 [Task]{@link google.cloud.tasks.v2beta2.Task}.
     *   The promise has a method named "cancel" which cancels the ongoing API call.
     */
    createTask(request, optionsOrCallback, callback) {
        request = request || {};
        let 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'] = gax.routingHeader.fromParams({
            parent: request.parent || '',
        });
        return this._innerApiCalls.createTask(request, options, callback);
    }
    /**
     * Deletes a task.
     *
     * A task can be deleted if it is scheduled or dispatched. A task
     * cannot be deleted if it has completed successfully or permanently
     * failed.
     *
     * @param {Object} request
     *   The request object that will be sent.
     * @param {string} request.name
     *   Required. The task name. For example:
     *   `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_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 [Empty]{@link google.protobuf.Empty}.
     *   The promise has a method named "cancel" which cancels the ongoing API call.
     */
    deleteTask(request, optionsOrCallback, callback) {
        request = request || {};
        let 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'] = gax.routingHeader.fromParams({
            name: request.name || '',
        });
        return this._innerApiCalls.deleteTask(request, options, callback);
    }
    /**
     * Leases tasks from a pull queue for
     * [lease_duration][google.cloud.tasks.v2beta2.LeaseTasksRequest.lease_duration].
     *
     * This method is invoked by the worker to obtain a lease. The
     * worker must acknowledge the task via
     * [AcknowledgeTask][google.cloud.tasks.v2beta2.CloudTasks.AcknowledgeTask] after they have
     * performed the work associated with the task.
     *
     * The [payload][google.cloud.tasks.v2beta2.PullMessage.payload] is intended to store data that
     * the worker needs to perform the work associated with the task. To
     * return the payloads in the [response][google.cloud.tasks.v2beta2.LeaseTasksResponse], set
     * [response_view][google.cloud.tasks.v2beta2.LeaseTasksRequest.response_view] to
     * [FULL][google.cloud.tasks.v2beta2.Task.View.FULL].
     *
     * A maximum of 10 qps of [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks]
     * requests are allowed per
     * queue. [RESOURCE_EXHAUSTED][google.rpc.Code.RESOURCE_EXHAUSTED]
     * is returned when this limit is
     * exceeded. [RESOURCE_EXHAUSTED][google.rpc.Code.RESOURCE_EXHAUSTED]
     * is also returned when
     * [max_tasks_dispatched_per_second][google.cloud.tasks.v2beta2.RateLimits.max_tasks_dispatched_per_second]
     * is exceeded.
     *
     * @param {Object} request
     *   The request object that will be sent.
     * @param {string} request.parent
     *   Required. The queue name. For example:
     *   `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`
     * @param {number} request.maxTasks
     *   The maximum number of tasks to lease.
     *
     *   The system will make a best effort to return as close to as
     *   `max_tasks` as possible.
     *
     *   The largest that `max_tasks` can be is 1000.
     *
     *   The maximum total size of a [lease tasks response][google.cloud.tasks.v2beta2.LeaseTasksResponse] is
     *   32 MB. If the sum of all task sizes requested reaches this limit,
     *   fewer tasks than requested are returned.
     * @param {google.protobuf.Duration} request.leaseDuration
     *   Required. The duration of the lease.
     *
     *   Each task returned in the [response][google.cloud.tasks.v2beta2.LeaseTasksResponse] will
     *   have its [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] set to the current
     *   time plus the `lease_duration`. The task is leased until its
     *   [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time]; thus, the task will not be
     *   returned to another [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks] call
     *   before its [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time].
     *
     *
     *   After the worker has successfully finished the work associated
     *   with the task, the worker must call via
     *   [AcknowledgeTask][google.cloud.tasks.v2beta2.CloudTasks.AcknowledgeTask] before the
     *   [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time]. Otherwise the task will be
     *   returned to a later [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks] call so
     *   that another worker can retry it.
     *
     *   The maximum lease duration is 1 week.
     *   `lease_duration` will be truncated to the nearest second.
     * @param {google.cloud.tasks.v2beta2.Task.View} request.responseView
     *   The response_view specifies which subset of the [Task][google.cloud.tasks.v2beta2.Task] will be
     *   returned.
     *
     *   By default response_view is [BASIC][google.cloud.tasks.v2beta2.Task.View.BASIC]; not all
     *   information is retrieved by default because some data, such as
     *   payloads, might be desirable to return only when needed because
     *   of its large size or because of the sensitivity of data that it
     *   contains.
     *
     *   Authorization for [FULL][google.cloud.tasks.v2beta2.Task.View.FULL] requires
     *   `cloudtasks.tasks.fullView` [Google IAM](https://cloud.google.com/iam/)
     *   permission on the [Task][google.cloud.tasks.v2beta2.Task] resource.
     * @param {string} request.filter
     *   `filter` can be used to specify a subset of tasks to lease.
     *
     *   When `filter` is set to `tag=<my-tag>` then the
     *   [response][google.cloud.tasks.v2beta2.LeaseTasksResponse] will contain only tasks whose
     *   [tag][google.cloud.tasks.v2beta2.PullMessage.tag] is equal to `<my-tag>`. `<my-tag>` must be
     *   less than 500 characters.
     *
     *   When `filter` is set to `tag_function=oldest_tag()`, only tasks which have
     *   the same tag as the task with the oldest
     *   [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] will be returned.
     *
     *   Grammar Syntax:
     *
     *   * `filter = "tag=" tag | "tag_function=" function`
     *
     *   * `tag = string`
     *
     *   * `function = "oldest_tag()"`
     *
     *   The `oldest_tag()` function returns tasks which have the same tag as the
     *   oldest task (ordered by schedule time).
     *
     *   SDK compatibility: Although the SDK allows tags to be either
     *   string or
     *   [bytes](https://cloud.google.com/appengine/docs/standard/java/javadoc/com/google/appengine/api/taskqueue/TaskOptions.html#tag-byte:A-),
     *   only UTF-8 encoded tags can be used in Cloud Tasks. Tag which
     *   aren't UTF-8 encoded can't be used in the
     *   [filter][google.cloud.tasks.v2beta2.LeaseTasksRequest.filter] and the task's
     *   [tag][google.cloud.tasks.v2beta2.PullMessage.tag] will be displayed as empty in Cloud Tasks.
     * @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 [LeaseTasksResponse]{@link google.cloud.tasks.v2beta2.LeaseTasksResponse}.
     *   The promise has a method named "cancel" which cancels the ongoing API call.
     */
    leaseTasks(request, optionsOrCallback, callback) {
        request = request || {};
        let 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'] = gax.routingHeader.fromParams({
            parent: request.parent || '',
        });
        return this._innerApiCalls.leaseTasks(request, options, callback);
    }
    /**
     * Acknowledges a pull task.
     *
     * The worker, that is, the entity that
     * [leased][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks] this task must call this method
     * to indicate that the work associated with the task has finished.
     *
     * The worker must acknowledge a task within the
     * [lease_duration][google.cloud.tasks.v2beta2.LeaseTasksRequest.lease_duration] or the lease
     * will expire and the task will become available to be leased
     * again. After the task is acknowledged, it will not be returned
     * by a later [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks],
     * [GetTask][google.cloud.tasks.v2beta2.CloudTasks.GetTask], or
     * [ListTasks][google.cloud.tasks.v2beta2.CloudTasks.ListTasks].
     *
     * @param {Object} request
     *   The request object that will be sent.
     * @param {string} request.name
     *   Required. The task name. For example:
     *   `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`
     * @param {google.protobuf.Timestamp} request.scheduleTime
     *   Required. The task's current schedule time, available in the
     *   [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] returned by
     *   [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks] response or
     *   [RenewLease][google.cloud.tasks.v2beta2.CloudTasks.RenewLease] response. This restriction is
     *   to ensure that your worker currently holds the lease.
     * @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 [Empty]{@link google.protobuf.Empty}.
     *   The promise has a method named "cancel" which cancels the ongoing API call.
     */
    acknowledgeTask(request, optionsOrCallback, callback) {
        request = request || {};
        let 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'] = gax.routingHeader.fromParams({
            name: request.name || '',
        });
        return this._innerApiCalls.acknowledgeTask(request, options, callback);
    }
    /**
     * Renew the current lease of a pull task.
     *
     * The worker can use this method to extend the lease by a new
     * duration, starting from now. The new task lease will be
     * returned in the task's [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time].
     *
     * @param {Object} request
     *   The request object that will be sent.
     * @param {string} request.name
     *   Required. The task name. For example:
     *   `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`
     * @param {google.protobuf.Timestamp} request.scheduleTime
     *   Required. The task's current schedule time, available in the
     *   [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] returned by
     *   [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks] response or
     *   [RenewLease][google.cloud.tasks.v2beta2.CloudTasks.RenewLease] response. This restriction is
     *   to ensure that your worker currently holds the lease.
     * @param {google.protobuf.Duration} request.leaseDuration
     *   Required. The desired new lease duration, starting from now.
     *
     *
     *   The maximum lease duration is 1 week.
     *   `lease_duration` will be truncated to the nearest second.
     * @param {google.cloud.tasks.v2beta2.Task.View} request.responseView
     *   The response_view specifies which subset of the [Task][google.cloud.tasks.v2beta2.Task] will be
     *   returned.
     *
     *   By default response_view is [BASIC][google.cloud.tasks.v2beta2.Task.View.BASIC]; not all
     *   information is retrieved by default because some data, such as
     *   payloads, might be desirable to return only when needed because
     *   of its large size or because of the sensitivity of data that it
     *   contains.
     *
     *   Authorization for [FULL][google.cloud.tasks.v2beta2.Task.View.FULL] requires
     *   `cloudtasks.tasks.fullView` [Google IAM](https://cloud.google.com/iam/)
     *   permission on the [Task][google.cloud.tasks.v2beta2.Task] resource.
     * @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 [Task]{@link google.cloud.tasks.v2beta2.Task}.
     *   The promise has a method named "cancel" which cancels the ongoing API call.
     */
    renewLease(request, optionsOrCallback, callback) {
        request = request || {};
        let 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'] = gax.routingHeader.fromParams({
            name: request.name || '',
        });
        return this._innerApiCalls.renewLease(request, options, callback);
    }
    /**
     * Cancel a pull task's lease.
     *
     * The worker can use this method to cancel a task's lease by
     * setting its [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] to now. This will
     * make the task available to be leased to the next caller of
     * [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks].
     *
     * @param {Object} request
     *   The request object that will be sent.
     * @param {string} request.name
     *   Required. The task name. For example:
     *   `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`
     * @param {google.protobuf.Timestamp} request.scheduleTime
     *   Required. The task's current schedule time, available in the
     *   [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] returned by
     *   [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks] response or
     *   [RenewLease][google.cloud.tasks.v2beta2.CloudTasks.RenewLease] response. This restriction is
     *   to ensure that your worker currently holds the lease.
     * @param {google.cloud.tasks.v2beta2.Task.View} request.responseView
     *   The response_view specifies which subset of the [Task][google.cloud.tasks.v2beta2.Task] will be
     *   returned.
     *
     *   By default response_view is [BASIC][google.cloud.tasks.v2beta2.Task.View.BASIC]; not all
     *   information is retrieved by default because some data, such as
     *   payloads, might be desirable to return only when needed because
     *   of its large size or because of the sensitivity of data that it
     *   contains.
     *
     *   Authorization for [FULL][google.cloud.tasks.v2beta2.Task.View.FULL] requires
     *   `cloudtasks.tasks.fullView` [Google IAM](https://cloud.google.com/iam/)
     *   permission on the [Task][google.cloud.tasks.v2beta2.Task] resource.
     * @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 [Task]{@link google.cloud.tasks.v2beta2.Task}.
     *   The promise has a method named "cancel" which cancels the ongoing API call.
     */
    cancelLease(request, optionsOrCallback, callback) {
        request = request || {};
        let 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'] = gax.routingHeader.fromParams({
            name: request.name || '',
        });
        return this._innerApiCalls.cancelLease(request, options, callback);
    }
    /**
     * Forces a task to run now.
     *
     * When this method is called, Cloud Tasks will dispatch the task, even if
     * the task is already running, the queue has reached its [RateLimits][google.cloud.tasks.v2beta2.RateLimits] or
     * is [PAUSED][google.cloud.tasks.v2beta2.Queue.State.PAUSED].
     *
     * This command is meant to be used for manual debugging. For
     * example, [RunTask][google.cloud.tasks.v2beta2.CloudTasks.RunTask] can be used to retry a failed
     * task after a fix has been made or to manually force a task to be
     * dispatched now.
     *
     * The dispatched task is returned. That is, the task that is returned
     * contains the [status][google.cloud.tasks.v2beta2.Task.status] after the task is dispatched but
     * before the task is received by its target.
     *
     * If Cloud Tasks receives a successful response from the task's
     * target, then the task will be deleted; otherwise the task's
     * [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] will be reset to the time that
     * [RunTask][google.cloud.tasks.v2beta2.CloudTasks.RunTask] was called plus the retry delay specified
     * in the queue's [RetryConfig][google.cloud.tasks.v2beta2.RetryConfig].
     *
     * [RunTask][google.cloud.tasks.v2beta2.CloudTasks.RunTask] returns
     * [NOT_FOUND][google.rpc.Code.NOT_FOUND] when it is called on a
     * task that has already succeeded or permanently failed.
     *
     * [RunTask][google.cloud.tasks.v2beta2.CloudTasks.RunTask] cannot be called on a
     * [pull task][google.cloud.tasks.v2beta2.PullMessage].
     *
     * @param {Object} request
     *   The request object that will be sent.
     * @param {string} request.name
     *   Required. The task name. For example:
     *   `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`
     * @param {google.cloud.tasks.v2beta2.Task.View} request.responseView
     *   The response_view specifies which subset of the [Task][google.cloud.tasks.v2beta2.Task] will be
     *   returned.
     *
     *   By default response_view is [BASIC][google.cloud.tasks.v2beta2.Task.View.BASIC]; not all
     *   information is retrieved by default because some data, such as
     *   payloads, might be desirable to return only when needed because
     *   of its large size or because of the sensitivity of data that it
     *   contains.
     *
     *   Authorization for [FULL][google.cloud.tasks.v2beta2.Task.View.FULL] requires
     *   `cloudtasks.tasks.fullView` [Google IAM](https://cloud.google.com/iam/)
     *   permission on the [Task][google.cloud.tasks.v2beta2.Task] resource.
     * @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 [Task]{@link google.cloud.tasks.v2beta2.Task}.
     *   The promise has a method named "cancel" which cancels the ongoing API call.
     */
    runTask(request, optionsOrCallback, callback) {
        request = request || {};
        let 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'] = gax.routingHeader.fromParams({
            name: request.name || '',
        });
        return this._innerApiCalls.runTask(request, options, callback);
    }
    /**
     * Lists queues.
     *
     * Queues are returned in lexicographical order.
     *
     * @param {Object} request
     *   The request object that will be sent.
     * @param {string} request.parent
     *   Required. The location name.
     *   For example: `projects/PROJECT_ID/locations/LOCATION_ID`
     * @param {string} request.filter
     *   `filter` can be used to specify a subset of queues. Any [Queue][google.cloud.tasks.v2beta2.Queue]
     *   field can be used as a filter and several operators as supported.
     *   For example: `<=, <, >=, >, !=, =, :`. The filter syntax is the same as
     *   described in
     *   [Stackdriver's Advanced Logs
     *   Filters](https://cloud.google.com/logging/docs/view/advanced_filters).
     *
     *   Sample filter "app_engine_http_target: *".
     *
     *   Note that using filters might cause fewer queues than the
     *   requested_page size to be returned.
     * @param {number} request.pageSize
     *   Requested page size.
     *
     *   The maximum page size is 9800. If unspecified, the page size will
     *   be the maximum. Fewer queues than requested might be returned,
     *   even if more queues exist; use the
     *   [next_page_token][google.cloud.tasks.v2beta2.ListQueuesResponse.next_page_token] in the
     *   response to determine if more queues exist.
     * @param {string} request.pageToken
     *   A token identifying the page of results to return.
     *
     *   To request the first page results, page_token must be empty. To
     *   request the next page of results, page_token must be the value of
     *   [next_page_token][google.cloud.tasks.v2beta2.ListQueuesResponse.next_page_token] returned
     *   from the previous call to [ListQueues][google.cloud.tasks.v2beta2.CloudTasks.ListQueues]
     *   method. It is an error to switch the value of the
     *   [filter][google.cloud.tasks.v2beta2.ListQueuesRequest.filter] while iterating through pages.
     * @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 Array of [Queue]{@link google.cloud.tasks.v2beta2.Queue}.
     *   The client library support auto-pagination by default: it will call the API as many
     *   times as needed and will merge results from all the pages into this array.
     *
     *   When autoPaginate: false is specified through options, the array has three elements.
     *   The first element is Array of [Queue]{@link google.cloud.tasks.v2beta2.Queue} that corresponds to
     *   the one page received from the API server.
     *   If the second element is not null it contains the request object of type [ListQueuesRequest]{@link google.cloud.tasks.v2beta2.ListQueuesRequest}
     *   that can be used to obtain the next page of the results.
     *   If it is null, the next page does not exist.
     *   The third element contains the raw response received from the API server. Its type is
     *   [ListQueuesResponse]{@link google.cloud.tasks.v2beta2.ListQueuesResponse}.
     *
     *   The promise has a method named "cancel" which cancels the ongoing API call.
     */
    listQueues(request, optionsOrCallback, callback) {
        request = request || {};
        let 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'] = gax.routingHeader.fromParams({
            parent: request.parent || '',
        });
        return this._innerApiCalls.listQueues(request, options, callback);
    }
    /**
     * Equivalent to {@link listQueues}, but returns a NodeJS Stream object.
     *
     * This fetches the paged responses for {@link listQueues} continuously
     * and invokes the callback registered for 'data' event for each element in the
     * responses.
     *
     * The returned object has 'end' method when no more elements are required.
     *
     * autoPaginate option will be ignored.
     *
     * @see {@link https://nodejs.org/api/stream.html}
     *
     * @param {Object} request
     *   The request object that will be sent.
     * @param {string} request.parent
     *   Required. The location name.
     *   For example: `projects/PROJECT_ID/locations/LOCATION_ID`
     * @param {string} request.filter
     *   `filter` can be used to specify a subset of queues. Any [Queue][google.cloud.tasks.v2beta2.Queue]
     *   field can be used as a filter and several operators as supported.
     *   For example: `<=, <, >=, >, !=, =, :`. The filter syntax is the same as
     *   described in
     *   [Stackdriver's Advanced Logs
     *   Filters](https://cloud.google.com/logging/docs/view/advanced_filters).
     *
     *   Sample filter "app_engine_http_target: *".
     *
     *   Note that using filters might cause fewer queues than the
     *   requested_page size to be returned.
     * @param {number} request.pageSize
     *   Requested page size.
     *
     *   The maximum page size is 9800. If unspecified, the page size will
     *   be the maximum. Fewer queues than requested might be returned,
     *   even if more queues exist; use the
     *   [next_page_token][google.cloud.tasks.v2beta2.ListQueuesResponse.next_page_token] in the
     *   response to determine if more queues exist.
     * @param {string} request.pageToken
     *   A token identifying the page of results to return.
     *
     *   To request the first page results, page_token must be empty. To
     *   request the next page of results, page_token must be the value of
     *   [next_page_token][google.cloud.tasks.v2beta2.ListQueuesResponse.next_page_token] returned
     *   from the previous call to [ListQueues][google.cloud.tasks.v2beta2.CloudTasks.ListQueues]
     *   method. It is an error to switch the value of the
     *   [filter][google.cloud.tasks.v2beta2.ListQueuesRequest.filter] while iterating through pages.
     * @param {object} [options]
     *   Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
     * @returns {Stream}
     *   An object stream which emits an object representing [Queue]{@link google.cloud.tasks.v2beta2.Queue} on 'data' event.
     */
    listQueuesStream(request, options) {
        request = request || {};
        const callSettings = new gax.CallSettings(options);
        return this._descriptors.page.listQueues.createStream(this._innerApiCalls.listQueues, request, callSettings);
    }
    /**
     * Lists the tasks in a queue.
     *
     * By default, only the [BASIC][google.cloud.tasks.v2beta2.Task.View.BASIC] view is retrieved
     * due to performance considerations;
     * [response_view][google.cloud.tasks.v2beta2.ListTasksRequest.response_view] controls the
     * subset of information which is returned.
     *
     * The tasks may be returned in any order. The ordering may change at any
     * time.
     *
     * @param {Object} request
     *   The request object that will be sent.
     * @param {string} request.parent
     *   Required. The queue name. For example:
     *   `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`
     * @param {google.cloud.tasks.v2beta2.Task.View} request.responseView
     *   The response_view specifies which subset of the [Task][google.cloud.tasks.v2beta2.Task] will be
     *   returned.
     *
     *   By default response_view is [BASIC][google.cloud.tasks.v2beta2.Task.View.BASIC]; not all
     *   information is retrieved by default because some data, such as
     *   payloads, might be desirable to return only when needed because
     *   of its large size or because of the sensitivity of data that it
     *   contains.
     *
     *   Authorization for [FULL][google.cloud.tasks.v2beta2.Task.View.FULL] requires
     *   `cloudtasks.tasks.fullView` [Google IAM](https://cloud.google.com/iam/)
     *   permission on the [Task][google.cloud.tasks.v2beta2.Task] resource.
     * @param {number} request.pageSize
     *   Maximum page size.
     *
     *   Fewer tasks than requested might be returned, even if more tasks exist; use
     *   [next_page_token][google.cloud.tasks.v2beta2.ListTasksResponse.next_page_token] in the response to
     *   determine if more tasks exist.
     *
     *   The maximum page size is 1000. If unspecified, the page size will be the
     *   maximum.
     * @param {string} request.pageToken
     *   A token identifying the page of results to return.
     *
     *   To request the first page results, page_token must be empty. To
     *   request the next page of results, page_token must be the value of
     *   [next_page_token][google.cloud.tasks.v2beta2.ListTasksResponse.next_page_token] returned
     *   from the previous call to [ListTasks][google.cloud.tasks.v2beta2.CloudTasks.ListTasks]
     *   method.
     *
     *   The page token is valid for only 2 hours.
     * @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 Array of [Task]{@link google.cloud.tasks.v2beta2.Task}.
     *   The client library support auto-pagination by default: it will call the API as many
     *   times as needed and will merge results from all the pages into this array.
     *
     *   When autoPaginate: false is specified through options, the array has three elements.
     *   The first element is Array of [Task]{@link google.cloud.tasks.v2beta2.Task} that corresponds to
     *   the one page received from the API server.
     *   If the second element is not null it contains the request object of type [ListTasksRequest]{@link google.cloud.tasks.v2beta2.ListTasksRequest}
     *   that can be used to obtain the next page of the results.
     *   If it is null, the next page does not exist.
     *   The third element contains the raw response received from the API server. Its type is
     *   [ListTasksResponse]{@link google.cloud.tasks.v2beta2.ListTasksResponse}.
     *
     *   The promise has a method named "cancel" which cancels the ongoing API call.
     */
    listTasks(request, optionsOrCallback, callback) {
        request = request || {};
        let 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'] = gax.routingHeader.fromParams({
            parent: request.parent || '',
        });
        return this._innerApiCalls.listTasks(request, options, callback);
    }
    /**
     * Equivalent to {@link listTasks}, but returns a NodeJS Stream object.
     *
     * This fetches the paged responses for {@link listTasks} continuously
     * and invokes the callback registered for 'data' event for each element in the
     * responses.
     *
     * The returned object has 'end' method when no more elements are required.
     *
     * autoPaginate option will be ignored.
     *
     * @see {@link https://nodejs.org/api/stream.html}
     *
     * @param {Object} request
     *   The request object that will be sent.
     * @param {string} request.parent
     *   Required. The queue name. For example:
     *   `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`
     * @param {google.cloud.tasks.v2beta2.Task.View} request.responseView
     *   The response_view specifies which subset of the [Task][google.cloud.tasks.v2beta2.Task] will be
     *   returned.
     *
     *   By default response_view is [BASIC][google.cloud.tasks.v2beta2.Task.View.BASIC]; not all
     *   information is retrieved by default because some data, such as
     *   payloads, might be desirable to return only when needed because
     *   of its large size or because of the sensitivity of data that it
     *   contains.
     *
     *   Authorization for [FULL][google.cloud.tasks.v2beta2.Task.View.FULL] requires
     *   `cloudtasks.tasks.fullView` [Google IAM](https://cloud.google.com/iam/)
     *   permission on the [Task][google.cloud.tasks.v2beta2.Task] resource.
     * @param {number} request.pageSize
     *   Maximum page size.
     *
     *   Fewer tasks than requested might be returned, even if more tasks exist; use
     *   [next_page_token][google.cloud.tasks.v2beta2.ListTasksResponse.next_page_token] in the response to
     *   determine if more tasks exist.
     *
     *   The maximum page size is 1000. If unspecified, the page size will be the
     *   maximum.
     * @param {string} request.pageToken
     *   A token identifying the page of results to return.
     *
     *   To request the first page results, page_token must be empty. To
     *   request the next page of results, page_token must be the value of
     *   [next_page_token][google.cloud.tasks.v2beta2.ListTasksResponse.next_page_token] returned
     *   from the previous call to [ListTasks][google.cloud.tasks.v2beta2.CloudTasks.ListTasks]
     *   method.
     *
     *   The page token is valid for only 2 hours.
     * @param {object} [options]
     *   Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
     * @returns {Stream}
     *   An object stream which emits an object representing [Task]{@link google.cloud.tasks.v2beta2.Task} on 'data' event.
     */
    listTasksStream(request, options) {
        request = request || {};
        const callSettings = new gax.CallSettings(options);
        return this._descriptors.page.listTasks.createStream(this._innerApiCalls.listTasks, request, callSettings);
    }
    // --------------------
    // -- Path templates --
    // --------------------
    /**
     * Return a fully-qualified project resource name string.
     *
     * @param {string} project
     * @returns {string} Resource name string.
     */
    projectPath(project) {
        return this._pathTemplates.projectPathTemplate.render({
            project,
        });
    }
    /**
     * Parse the project from Project resource.
     *
     * @param {string} projectName
     *   A fully-qualified path representing Project resource.
     * @returns {string} A string representing the project.
     */
    matchProjectFromProjectName(projectName) {
        return this._pathTemplates.projectPathTemplate.match(projectName).project;
    }
    /**
     * Return a fully-qualified location resource name string.
     *
     * @param {string} project
     * @param {string} location
     * @returns {string} Resource name string.
     */
    locationPath(project, location) {
        return this._pathTemplates.locationPathTemplate.render({
            project,
            location,
        });
    }
    /**
     * Parse the project from Location resource.
     *
     * @param {string} locationName
     *   A fully-qualified path representing Location resource.
     * @returns {string} A string representing the project.
     */
    matchProjectFromLocationName(locationName) {
        return this._pathTemplates.locationPathTemplate.match(locationName).project;
    }
    /**
     * Parse the location from Location resource.
     *
     * @param {string} locationName
     *   A fully-qualified path representing Location resource.
     * @returns {string} A string representing the location.
     */
    matchLocationFromLocationName(locationName) {
        return this._pathTemplates.locationPathTemplate.match(locationName)
            .location;
    }
    /**
     * Return a fully-qualified queue resource name string.
     *
     * @param {string} project
     * @param {string} location
     * @param {string} queue
     * @returns {string} Resource name string.
     */
    queuePath(project, location, queue) {
        return this._pathTemplates.queuePathTemplate.render({
            project,
            location,
            queue,
        });
    }
    /**
     * Parse the project from Queue resource.
     *
     * @param {string} queueName
     *   A fully-qualified path representing Queue resource.
     * @returns {string} A string representing the project.
     */
    matchProjectFromQueueName(queueName) {
        return this._pathTemplates.queuePathTemplate.match(queueName).project;
    }
    /**
     * Parse the location from Queue resource.
     *
     * @param {string} queueName
     *   A fully-qualified path representing Queue resource.
     * @returns {string} A string representing the location.
     */
    matchLocationFromQueueName(queueName) {
        return this._pathTemplates.queuePathTemplate.match(queueName).location;
    }
    /**
     * Parse the queue from Queue resource.
     *
     * @param {string} queueName
     *   A fully-qualified path representing Queue resource.
     * @returns {string} A string representing the queue.
     */
    matchQueueFromQueueName(queueName) {
        return this._pathTemplates.queuePathTemplate.match(queueName).queue;
    }
    /**
     * Return a fully-qualified task resource name string.
     *
     * @param {string} project
     * @param {string} location
     * @param {string} queue
     * @param {string} task
     * @returns {string} Resource name string.
     */
    taskPath(project, location, queue, task) {
        return this._pathTemplates.taskPathTemplate.render({
            project,
            location,
            queue,
            task,
        });
    }
    /**
     * Parse the project from Task resource.
     *
     * @param {string} taskName
     *   A fully-qualified path representing Task resource.
     * @returns {string} A string representing the project.
     */
    matchProjectFromTaskName(taskName) {
        return this._pathTemplates.taskPathTemplate.match(taskName).project;
    }
    /**
     * Parse the location from Task resource.
     *
     * @param {string} taskName
     *   A fully-qualified path representing Task resource.
     * @returns {string} A string representing the location.
     */
    matchLocationFromTaskName(taskName) {
        return this._pathTemplates.taskPathTemplate.match(taskName).location;
    }
    /**
     * Parse the queue from Task resource.
     *
     * @param {string} taskName
     *   A fully-qualified path representing Task resource.
     * @returns {string} A string representing the queue.
     */
    matchQueueFromTaskName(taskName) {
        return this._pathTemplates.taskPathTemplate.match(taskName).queue;
    }
    /**
     * Parse the task from Task resource.
     *
     * @param {string} taskName
     *   A fully-qualified path representing Task resource.
     * @returns {string} A string representing the task.
     */
    matchTaskFromTaskName(taskName) {
        return this._pathTemplates.taskPathTemplate.match(taskName).task;
    }
    /**
     * Terminate the GRPC channel and close the client.
     *
     * The client will no longer be usable and all future behavior is undefined.
     */
    close() {
        if (!this._terminated) {
            return this.cloudTasksStub.then(stub => {
                this._terminated = true;
                stub.close();
            });
        }
        return Promise.resolve();
    }
}
exports.CloudTasksClient = CloudTasksClient;
//# sourceMappingURL=cloud_tasks_client.js.map