// 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.
'use strict';
const gapicConfig = require('./cloud_tasks_client_config.json');
const gax = require('google-gax');
const path = require('path');
const VERSION = require('../../package.json').version;
/**
* Cloud Tasks allows developers to manage the execution of background
* work in their applications.
*
* @class
* @memberof v2beta3
*/
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) {
opts = opts || {};
this._descriptors = {};
if (global.isBrowser) {
// If we're in browser, we use gRPC fallback.
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 = !global.isBrowser && opts.fallback ? gax.fallback : gax;
const servicePath =
opts.servicePath || opts.apiEndpoint || this.constructor.servicePath;
// Ensure that options include the service address and port.
opts = Object.assign(
{
clientConfig: {},
port: this.constructor.port,
servicePath,
},
opts
);
// 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 = [];
if (typeof process !== 'undefined' && 'versions' in process) {
clientHeader.push(`gl-node/${process.versions.node}`);
}
clientHeader.push(`gax/${gaxModule.version}`);
if (opts.fallback) {
clientHeader.push(`gl-web/${gaxModule.version}`);
} else {
clientHeader.push(`grpc/${gaxGrpc.grpcVersion}`);
}
clientHeader.push(`gapic/${VERSION}`);
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 = {
locationPathTemplate: new gaxModule.PathTemplate(
'projects/{project}/locations/{location}'
),
projectPathTemplate: new gaxModule.PathTemplate('projects/{project}'),
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.v2beta3.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.v2beta3.CloudTasks.
const cloudTasksStub = gaxGrpc.createStub(
opts.fallback
? protos.lookupService('google.cloud.tasks.v2beta3.CloudTasks')
: protos.google.cloud.tasks.v2beta3.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',
'runTask',
];
for (const methodName of cloudTasksStubMethods) {
const innerCallPromise = cloudTasksStub.then(
stub => (...args) => {
return stub[methodName].apply(stub, args);
},
err => () => {
throw err;
}
);
this._innerApiCalls[methodName] = gaxModule.createApiCall(
innerCallPromise,
defaults[methodName],
this._descriptors.page[methodName]
);
}
}
/**
* 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) {
return this.auth.getProjectId(callback);
}
// -------------------
// -- Service calls --
// -------------------
/**
* 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
* 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 "state: PAUSED".
*
* Note that using filters might cause fewer queues than the
* requested page_size to be returned.
* @param {number} [request.pageSize]
* The maximum number of resources contained in the underlying API
* response. If page streaming is performed per-resource, this
* parameter does not affect the return value. If page streaming is
* performed per-page, this determines the maximum number of
* resources in a page.
* @param {Object} [options]
* Optional parameters. You can override the default settings for this call, e.g, timeout,
* retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html} for the details.
* @param {function(?Error, ?Array, ?Object, ?Object)} [callback]
* The function which will be called with the result of the API call.
*
* The second parameter to the callback is Array of [Queue]{@link google.cloud.tasks.v2beta3.Queue}.
*
* When autoPaginate: false is specified through options, it contains the result
* in a single response. If the response indicates the next page exists, the third
* parameter is set to be used for the next request object. The fourth parameter keeps
* the raw response object of an object representing [ListQueuesResponse]{@link google.cloud.tasks.v2beta3.ListQueuesResponse}.
* @returns {Promise} - The promise which resolves to an array.
* The first element of the array is Array of [Queue]{@link google.cloud.tasks.v2beta3.Queue}.
*
* When autoPaginate: false is specified through options, the array has three elements.
* The first element is Array of [Queue]{@link google.cloud.tasks.v2beta3.Queue} in a single response.
* The second element is the next request object if the response
* indicates the next page exists, or null. The third element is
* an object representing [ListQueuesResponse]{@link google.cloud.tasks.v2beta3.ListQueuesResponse}.
*
* The promise has a method named "cancel" which cancels the ongoing API call.
*
* @example
*
* const tasks = require('tasks.v2beta3');
*
* const client = new tasks.v2beta3.CloudTasksClient({
* // optional auth parameters.
* });
*
* // Iterate over all elements.
* const formattedParent = client.locationPath('[PROJECT]', '[LOCATION]');
*
* client.listQueues({parent: formattedParent})
* .then(responses => {
* const resources = responses[0];
* for (const resource of resources) {
* // doThingsWith(resource)
* }
* })
* .catch(err => {
* console.error(err);
* });
*
* // Or obtain the paged response.
* const formattedParent = client.locationPath('[PROJECT]', '[LOCATION]');
*
*
* const options = {autoPaginate: false};
* const callback = responses => {
* // The actual resources in a response.
* const resources = responses[0];
* // The next request if the response shows that there are more responses.
* const nextRequest = responses[1];
* // The actual response object, if necessary.
* // const rawResponse = responses[2];
* for (const resource of resources) {
* // doThingsWith(resource);
* }
* if (nextRequest) {
* // Fetch the next page.
* return client.listQueues(nextRequest, options).then(callback);
* }
* }
* client.listQueues({parent: formattedParent}, options)
* .then(callback)
* .catch(err => {
* console.error(err);
* });
*/
listQueues(request, options, callback) {
if (options instanceof Function && callback === undefined) {
callback = options;
options = {};
}
request = request || {};
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
* 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 "state: PAUSED".
*
* Note that using filters might cause fewer queues than the
* requested page_size to be returned.
* @param {number} [request.pageSize]
* The maximum number of resources contained in the underlying API
* response. If page streaming is performed per-resource, this
* parameter does not affect the return value. If page streaming is
* performed per-page, this determines the maximum number of
* resources in a page.
* @param {Object} [options]
* Optional parameters. You can override the default settings for this call, e.g, timeout,
* retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html} for the details.
* @returns {Stream}
* An object stream which emits an object representing [Queue]{@link google.cloud.tasks.v2beta3.Queue} on 'data' event.
*
* @example
*
* const tasks = require('tasks.v2beta3');
*
* const client = new tasks.v2beta3.CloudTasksClient({
* // optional auth parameters.
* });
*
* const formattedParent = client.locationPath('[PROJECT]', '[LOCATION]');
* client.listQueuesStream({parent: formattedParent})
* .on('data', element => {
* // doThingsWith(element)
* }).on('error', err => {
* console.log(err);
* });
*/
listQueuesStream(request, options) {
options = options || {};
return this._descriptors.page.listQueues.createStream(
this._innerApiCalls.listQueues,
request,
options
);
}
/**
* 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]
* Optional parameters. You can override the default settings for this call, e.g, timeout,
* retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html} for the details.
* @param {function(?Error, ?Object)} [callback]
* The function which will be called with the result of the API call.
*
* The second parameter to the callback is an object representing [Queue]{@link google.cloud.tasks.v2beta3.Queue}.
* @returns {Promise} - The promise which resolves to an array.
* The first element of the array is an object representing [Queue]{@link google.cloud.tasks.v2beta3.Queue}.
* The promise has a method named "cancel" which cancels the ongoing API call.
*
* @example
*
* const tasks = require('tasks.v2beta3');
*
* const client = new tasks.v2beta3.CloudTasksClient({
* // optional auth parameters.
* });
*
* const formattedName = client.queuePath('[PROJECT]', '[LOCATION]', '[QUEUE]');
* client.getQueue({name: formattedName})
* .then(responses => {
* const response = responses[0];
* // doThingsWith(response)
* })
* .catch(err => {
* console.error(err);
* });
*/
getQueue(request, options, callback) {
if (options instanceof Function && callback === undefined) {
callback = options;
options = {};
}
request = request || {};
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.
* @param {Object} request.queue
* Required. The queue to create.
*
* Queue's name cannot be the same as an existing queue.
*
* This object should have the same structure as [Queue]{@link google.cloud.tasks.v2beta3.Queue}
* @param {Object} [options]
* Optional parameters. You can override the default settings for this call, e.g, timeout,
* retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html} for the details.
* @param {function(?Error, ?Object)} [callback]
* The function which will be called with the result of the API call.
*
* The second parameter to the callback is an object representing [Queue]{@link google.cloud.tasks.v2beta3.Queue}.
* @returns {Promise} - The promise which resolves to an array.
* The first element of the array is an object representing [Queue]{@link google.cloud.tasks.v2beta3.Queue}.
* The promise has a method named "cancel" which cancels the ongoing API call.
*
* @example
*
* const tasks = require('tasks.v2beta3');
*
* const client = new tasks.v2beta3.CloudTasksClient({
* // optional auth parameters.
* });
*
* const formattedParent = client.locationPath('[PROJECT]', '[LOCATION]');
* const queue = {};
* const request = {
* parent: formattedParent,
* queue: queue,
* };
* client.createQueue(request)
* .then(responses => {
* const response = responses[0];
* // doThingsWith(response)
* })
* .catch(err => {
* console.error(err);
* });
*/
createQueue(request, options, callback) {
if (options instanceof Function && callback === undefined) {
callback = options;
options = {};
}
request = request || {};
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 {Object} request.queue
* Required. The queue to create or update.
*
* The queue's 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 cannot be changed.
*
* This object should have the same structure as [Queue]{@link google.cloud.tasks.v2beta3.Queue}
* @param {Object} [request.updateMask]
* A mask used to specify which fields of the queue are being updated.
*
* If empty, then all fields will be updated.
*
* This object should have the same structure as [FieldMask]{@link google.protobuf.FieldMask}
* @param {Object} [options]
* Optional parameters. You can override the default settings for this call, e.g, timeout,
* retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html} for the details.
* @param {function(?Error, ?Object)} [callback]
* The function which will be called with the result of the API call.
*
* The second parameter to the callback is an object representing [Queue]{@link google.cloud.tasks.v2beta3.Queue}.
* @returns {Promise} - The promise which resolves to an array.
* The first element of the array is an object representing [Queue]{@link google.cloud.tasks.v2beta3.Queue}.
* The promise has a method named "cancel" which cancels the ongoing API call.
*
* @example
*
* const tasks = require('tasks.v2beta3');
*
* const client = new tasks.v2beta3.CloudTasksClient({
* // optional auth parameters.
* });
*
* const queue = {};
* client.updateQueue({queue: queue})
* .then(responses => {
* const response = responses[0];
* // doThingsWith(response)
* })
* .catch(err => {
* console.error(err);
* });
*/
updateQueue(request, options, callback) {
if (options instanceof Function && callback === undefined) {
callback = options;
options = {};
}
request = request || {};
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]
* Optional parameters. You can override the default settings for this call, e.g, timeout,
* retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html} for the details.
* @param {function(?Error)} [callback]
* The function which will be called with the result of the API call.
* @returns {Promise} - The promise which resolves when API call finishes.
* The promise has a method named "cancel" which cancels the ongoing API call.
*
* @example
*
* const tasks = require('tasks.v2beta3');
*
* const client = new tasks.v2beta3.CloudTasksClient({
* // optional auth parameters.
* });
*
* const formattedName = client.queuePath('[PROJECT]', '[LOCATION]', '[QUEUE]');
* client.deleteQueue({name: formattedName}).catch(err => {
* console.error(err);
* });
*/
deleteQueue(request, options, callback) {
if (options instanceof Function && callback === undefined) {
callback = options;
options = {};
}
request = request || {};
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]
* Optional parameters. You can override the default settings for this call, e.g, timeout,
* retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html} for the details.
* @param {function(?Error, ?Object)} [callback]
* The function which will be called with the result of the API call.
*
* The second parameter to the callback is an object representing [Queue]{@link google.cloud.tasks.v2beta3.Queue}.
* @returns {Promise} - The promise which resolves to an array.
* The first element of the array is an object representing [Queue]{@link google.cloud.tasks.v2beta3.Queue}.
* The promise has a method named "cancel" which cancels the ongoing API call.
*
* @example
*
* const tasks = require('tasks.v2beta3');
*
* const client = new tasks.v2beta3.CloudTasksClient({
* // optional auth parameters.
* });
*
* const formattedName = client.queuePath('[PROJECT]', '[LOCATION]', '[QUEUE]');
* client.purgeQueue({name: formattedName})
* .then(responses => {
* const response = responses[0];
* // doThingsWith(response)
* })
* .catch(err => {
* console.error(err);
* });
*/
purgeQueue(request, options, callback) {
if (options instanceof Function && callback === undefined) {
callback = options;
options = {};
}
request = request || {};
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. Tasks can still be added
* when the queue is paused. A queue is paused if its
* state is 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]
* Optional parameters. You can override the default settings for this call, e.g, timeout,
* retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html} for the details.
* @param {function(?Error, ?Object)} [callback]
* The function which will be called with the result of the API call.
*
* The second parameter to the callback is an object representing [Queue]{@link google.cloud.tasks.v2beta3.Queue}.
* @returns {Promise} - The promise which resolves to an array.
* The first element of the array is an object representing [Queue]{@link google.cloud.tasks.v2beta3.Queue}.
* The promise has a method named "cancel" which cancels the ongoing API call.
*
* @example
*
* const tasks = require('tasks.v2beta3');
*
* const client = new tasks.v2beta3.CloudTasksClient({
* // optional auth parameters.
* });
*
* const formattedName = client.queuePath('[PROJECT]', '[LOCATION]', '[QUEUE]');
* client.pauseQueue({name: formattedName})
* .then(responses => {
* const response = responses[0];
* // doThingsWith(response)
* })
* .catch(err => {
* console.error(err);
* });
*/
pauseQueue(request, options, callback) {
if (options instanceof Function && callback === undefined) {
callback = options;
options = {};
}
request = request || {};
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 or
* DISABLED. The state of a queue is stored
* in the queue's state; after calling this method it
* will be set to 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]
* Optional parameters. You can override the default settings for this call, e.g, timeout,
* retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html} for the details.
* @param {function(?Error, ?Object)} [callback]
* The function which will be called with the result of the API call.
*
* The second parameter to the callback is an object representing [Queue]{@link google.cloud.tasks.v2beta3.Queue}.
* @returns {Promise} - The promise which resolves to an array.
* The first element of the array is an object representing [Queue]{@link google.cloud.tasks.v2beta3.Queue}.
* The promise has a method named "cancel" which cancels the ongoing API call.
*
* @example
*
* const tasks = require('tasks.v2beta3');
*
* const client = new tasks.v2beta3.CloudTasksClient({
* // optional auth parameters.
* });
*
* const formattedName = client.queuePath('[PROJECT]', '[LOCATION]', '[QUEUE]');
* client.resumeQueue({name: formattedName})
* .then(responses => {
* const response = responses[0];
* // doThingsWith(response)
* })
* .catch(err => {
* console.error(err);
* });
*/
resumeQueue(request, options, callback) {
if (options instanceof Function && callback === undefined) {
callback = options;
options = {};
}
request = request || {};
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.
* 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 {Object} [request.options]
* OPTIONAL: A `GetPolicyOptions` object for specifying options to
* `GetIamPolicy`. This field is only used by Cloud IAM.
*
* This object should have the same structure as [GetPolicyOptions]{@link google.iam.v1.GetPolicyOptions}
* @param {Object} [options]
* Optional parameters. You can override the default settings for this call, e.g, timeout,
* retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html} for the details.
* @param {function(?Error, ?Object)} [callback]
* The function which will be called with the result of the API call.
*
* The second parameter to the callback is an object representing [Policy]{@link google.iam.v1.Policy}.
* @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.
*
* @example
*
* const tasks = require('tasks.v2beta3');
*
* const client = new tasks.v2beta3.CloudTasksClient({
* // optional auth parameters.
* });
*
* const formattedResource = client.queuePath('[PROJECT]', '[LOCATION]', '[QUEUE]');
* client.getIamPolicy({resource: formattedResource})
* .then(responses => {
* const response = responses[0];
* // doThingsWith(response)
* })
* .catch(err => {
* console.error(err);
* });
*/
getIamPolicy(request, options, callback) {
if (options instanceof Function && callback === undefined) {
callback = options;
options = {};
}
request = request || {};
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. 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 {string} request.resource
* REQUIRED: The resource for which the policy is being specified.
* See the operation documentation for the appropriate value for this field.
* @param {Object} request.policy
* REQUIRED: The complete policy to be applied to the `resource`. The size of
* the policy is limited to a few 10s of KB. An empty policy is a
* valid policy but certain Cloud Platform services (such as Projects)
* might reject them.
*
* This object should have the same structure as [Policy]{@link google.iam.v1.Policy}
* @param {Object} [options]
* Optional parameters. You can override the default settings for this call, e.g, timeout,
* retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html} for the details.
* @param {function(?Error, ?Object)} [callback]
* The function which will be called with the result of the API call.
*
* The second parameter to the callback is an object representing [Policy]{@link google.iam.v1.Policy}.
* @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.
*
* @example
*
* const tasks = require('tasks.v2beta3');
*
* const client = new tasks.v2beta3.CloudTasksClient({
* // optional auth parameters.
* });
*
* const formattedResource = client.queuePath('[PROJECT]', '[LOCATION]', '[QUEUE]');
* const policy = {};
* const request = {
* resource: formattedResource,
* policy: policy,
* };
* client.setIamPolicy(request)
* .then(responses => {
* const response = responses[0];
* // doThingsWith(response)
* })
* .catch(err => {
* console.error(err);
* });
*/
setIamPolicy(request, options, callback) {
if (options instanceof Function && callback === undefined) {
callback = options;
options = {};
}
request = request || {};
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.
* If the resource does not exist, this will return an empty set of
* permissions, not a 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 {string} request.resource
* REQUIRED: The resource for which the policy detail is being requested.
* See the operation documentation for the appropriate value for this field.
* @param {string[]} request.permissions
* The set of permissions to check for the `resource`. Permissions with
* wildcards (such as '*' or 'storage.*') are not allowed. For more
* information see
* [IAM Overview](https://cloud.google.com/iam/docs/overview#permissions).
* @param {Object} [options]
* Optional parameters. You can override the default settings for this call, e.g, timeout,
* retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html} for the details.
* @param {function(?Error, ?Object)} [callback]
* The function which will be called with the result of the API call.
*
* The second parameter to the callback is an object representing [TestIamPermissionsResponse]{@link google.iam.v1.TestIamPermissionsResponse}.
* @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.
*
* @example
*
* const tasks = require('tasks.v2beta3');
*
* const client = new tasks.v2beta3.CloudTasksClient({
* // optional auth parameters.
* });
*
* const formattedResource = client.queuePath('[PROJECT]', '[LOCATION]', '[QUEUE]');
* const permissions = [];
* const request = {
* resource: formattedResource,
* permissions: permissions,
* };
* client.testIamPermissions(request)
* .then(responses => {
* const response = responses[0];
* // doThingsWith(response)
* })
* .catch(err => {
* console.error(err);
* });
*/
testIamPermissions(request, options, callback) {
if (options instanceof Function && callback === undefined) {
callback = options;
options = {};
}
request = request || {};
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);
}
/**
* Lists the tasks in a queue.
*
* By default, only the BASIC view is retrieved
* due to performance considerations;
* 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 {number} [request.responseView]
* The response_view specifies which subset of the Task will be
* returned.
*
* By default response_view is 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 requires
* `cloudtasks.tasks.fullView` [Google IAM](https://cloud.google.com/iam/)
* permission on the Task resource.
*
* The number should be among the values of [View]{@link google.cloud.tasks.v2beta3.View}
* @param {number} [request.pageSize]
* The maximum number of resources contained in the underlying API
* response. If page streaming is performed per-resource, this
* parameter does not affect the return value. If page streaming is
* performed per-page, this determines the maximum number of
* resources in a page.
* @param {Object} [options]
* Optional parameters. You can override the default settings for this call, e.g, timeout,
* retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html} for the details.
* @param {function(?Error, ?Array, ?Object, ?Object)} [callback]
* The function which will be called with the result of the API call.
*
* The second parameter to the callback is Array of [Task]{@link google.cloud.tasks.v2beta3.Task}.
*
* When autoPaginate: false is specified through options, it contains the result
* in a single response. If the response indicates the next page exists, the third
* parameter is set to be used for the next request object. The fourth parameter keeps
* the raw response object of an object representing [ListTasksResponse]{@link google.cloud.tasks.v2beta3.ListTasksResponse}.
* @returns {Promise} - The promise which resolves to an array.
* The first element of the array is Array of [Task]{@link google.cloud.tasks.v2beta3.Task}.
*
* When autoPaginate: false is specified through options, the array has three elements.
* The first element is Array of [Task]{@link google.cloud.tasks.v2beta3.Task} in a single response.
* The second element is the next request object if the response
* indicates the next page exists, or null. The third element is
* an object representing [ListTasksResponse]{@link google.cloud.tasks.v2beta3.ListTasksResponse}.
*
* The promise has a method named "cancel" which cancels the ongoing API call.
*
* @example
*
* const tasks = require('tasks.v2beta3');
*
* const client = new tasks.v2beta3.CloudTasksClient({
* // optional auth parameters.
* });
*
* // Iterate over all elements.
* const formattedParent = client.queuePath('[PROJECT]', '[LOCATION]', '[QUEUE]');
*
* client.listTasks({parent: formattedParent})
* .then(responses => {
* const resources = responses[0];
* for (const resource of resources) {
* // doThingsWith(resource)
* }
* })
* .catch(err => {
* console.error(err);
* });
*
* // Or obtain the paged response.
* const formattedParent = client.queuePath('[PROJECT]', '[LOCATION]', '[QUEUE]');
*
*
* const options = {autoPaginate: false};
* const callback = responses => {
* // The actual resources in a response.
* const resources = responses[0];
* // The next request if the response shows that there are more responses.
* const nextRequest = responses[1];
* // The actual response object, if necessary.
* // const rawResponse = responses[2];
* for (const resource of resources) {
* // doThingsWith(resource);
* }
* if (nextRequest) {
* // Fetch the next page.
* return client.listTasks(nextRequest, options).then(callback);
* }
* }
* client.listTasks({parent: formattedParent}, options)
* .then(callback)
* .catch(err => {
* console.error(err);
* });
*/
listTasks(request, options, callback) {
if (options instanceof Function && callback === undefined) {
callback = options;
options = {};
}
request = request || {};
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 {number} [request.responseView]
* The response_view specifies which subset of the Task will be
* returned.
*
* By default response_view is 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 requires
* `cloudtasks.tasks.fullView` [Google IAM](https://cloud.google.com/iam/)
* permission on the Task resource.
*
* The number should be among the values of [View]{@link google.cloud.tasks.v2beta3.View}
* @param {number} [request.pageSize]
* The maximum number of resources contained in the underlying API
* response. If page streaming is performed per-resource, this
* parameter does not affect the return value. If page streaming is
* performed per-page, this determines the maximum number of
* resources in a page.
* @param {Object} [options]
* Optional parameters. You can override the default settings for this call, e.g, timeout,
* retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html} for the details.
* @returns {Stream}
* An object stream which emits an object representing [Task]{@link google.cloud.tasks.v2beta3.Task} on 'data' event.
*
* @example
*
* const tasks = require('tasks.v2beta3');
*
* const client = new tasks.v2beta3.CloudTasksClient({
* // optional auth parameters.
* });
*
* const formattedParent = client.queuePath('[PROJECT]', '[LOCATION]', '[QUEUE]');
* client.listTasksStream({parent: formattedParent})
* .on('data', element => {
* // doThingsWith(element)
* }).on('error', err => {
* console.log(err);
* });
*/
listTasksStream(request, options) {
options = options || {};
return this._descriptors.page.listTasks.createStream(
this._innerApiCalls.listTasks,
request,
options
);
}
/**
* 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 {number} [request.responseView]
* The response_view specifies which subset of the Task will be
* returned.
*
* By default response_view is 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 requires
* `cloudtasks.tasks.fullView` [Google IAM](https://cloud.google.com/iam/)
* permission on the Task resource.
*
* The number should be among the values of [View]{@link google.cloud.tasks.v2beta3.View}
* @param {Object} [options]
* Optional parameters. You can override the default settings for this call, e.g, timeout,
* retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html} for the details.
* @param {function(?Error, ?Object)} [callback]
* The function which will be called with the result of the API call.
*
* The second parameter to the callback is an object representing [Task]{@link google.cloud.tasks.v2beta3.Task}.
* @returns {Promise} - The promise which resolves to an array.
* The first element of the array is an object representing [Task]{@link google.cloud.tasks.v2beta3.Task}.
* The promise has a method named "cancel" which cancels the ongoing API call.
*
* @example
*
* const tasks = require('tasks.v2beta3');
*
* const client = new tasks.v2beta3.CloudTasksClient({
* // optional auth parameters.
* });
*
* const formattedName = client.taskPath('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]');
* client.getTask({name: formattedName})
* .then(responses => {
* const response = responses[0];
* // doThingsWith(response)
* })
* .catch(err => {
* console.error(err);
* });
*/
getTask(request, options, callback) {
if (options instanceof Function && callback === undefined) {
callback = options;
options = {};
}
request = request || {};
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.
*
* * The maximum task size is 100KB.
*
* @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 {Object} 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. 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.
*
* If 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 executed recently then the call will fail
* with 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 executed. 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 executed.
*
* Because there is an extra lookup cost to identify duplicate task
* names, these 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.
*
* This object should have the same structure as [Task]{@link google.cloud.tasks.v2beta3.Task}
* @param {number} [request.responseView]
* The response_view specifies which subset of the Task will be
* returned.
*
* By default response_view is 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 requires
* `cloudtasks.tasks.fullView` [Google IAM](https://cloud.google.com/iam/)
* permission on the Task resource.
*
* The number should be among the values of [View]{@link google.cloud.tasks.v2beta3.View}
* @param {Object} [options]
* Optional parameters. You can override the default settings for this call, e.g, timeout,
* retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html} for the details.
* @param {function(?Error, ?Object)} [callback]
* The function which will be called with the result of the API call.
*
* The second parameter to the callback is an object representing [Task]{@link google.cloud.tasks.v2beta3.Task}.
* @returns {Promise} - The promise which resolves to an array.
* The first element of the array is an object representing [Task]{@link google.cloud.tasks.v2beta3.Task}.
* The promise has a method named "cancel" which cancels the ongoing API call.
*
* @example
*
* const tasks = require('tasks.v2beta3');
*
* const client = new tasks.v2beta3.CloudTasksClient({
* // optional auth parameters.
* });
*
* const formattedParent = client.queuePath('[PROJECT]', '[LOCATION]', '[QUEUE]');
* const task = {};
* const request = {
* parent: formattedParent,
* task: task,
* };
* client.createTask(request)
* .then(responses => {
* const response = responses[0];
* // doThingsWith(response)
* })
* .catch(err => {
* console.error(err);
* });
*/
createTask(request, options, callback) {
if (options instanceof Function && callback === undefined) {
callback = options;
options = {};
}
request = request || {};
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 executed 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]
* Optional parameters. You can override the default settings for this call, e.g, timeout,
* retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html} for the details.
* @param {function(?Error)} [callback]
* The function which will be called with the result of the API call.
* @returns {Promise} - The promise which resolves when API call finishes.
* The promise has a method named "cancel" which cancels the ongoing API call.
*
* @example
*
* const tasks = require('tasks.v2beta3');
*
* const client = new tasks.v2beta3.CloudTasksClient({
* // optional auth parameters.
* });
*
* const formattedName = client.taskPath('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]');
* client.deleteTask({name: formattedName}).catch(err => {
* console.error(err);
* });
*/
deleteTask(request, options, callback) {
if (options instanceof Function && callback === undefined) {
callback = options;
options = {};
}
request = request || {};
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);
}
/**
* 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 or
* is PAUSED.
*
* This command is meant to be used for manual debugging. For
* example, 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 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 will be reset to the time that
* RunTask was called plus the retry delay specified
* in the queue's RetryConfig.
*
* RunTask returns
* NOT_FOUND when it is called on a
* task that has already succeeded 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 {number} [request.responseView]
* The response_view specifies which subset of the Task will be
* returned.
*
* By default response_view is 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 requires
* `cloudtasks.tasks.fullView` [Google IAM](https://cloud.google.com/iam/)
* permission on the Task resource.
*
* The number should be among the values of [View]{@link google.cloud.tasks.v2beta3.View}
* @param {Object} [options]
* Optional parameters. You can override the default settings for this call, e.g, timeout,
* retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html} for the details.
* @param {function(?Error, ?Object)} [callback]
* The function which will be called with the result of the API call.
*
* The second parameter to the callback is an object representing [Task]{@link google.cloud.tasks.v2beta3.Task}.
* @returns {Promise} - The promise which resolves to an array.
* The first element of the array is an object representing [Task]{@link google.cloud.tasks.v2beta3.Task}.
* The promise has a method named "cancel" which cancels the ongoing API call.
*
* @example
*
* const tasks = require('tasks.v2beta3');
*
* const client = new tasks.v2beta3.CloudTasksClient({
* // optional auth parameters.
* });
*
* const formattedName = client.taskPath('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]');
* client.runTask({name: formattedName})
* .then(responses => {
* const response = responses[0];
* // doThingsWith(response)
* })
* .catch(err => {
* console.error(err);
* });
*/
runTask(request, options, callback) {
if (options instanceof Function && callback === undefined) {
callback = options;
options = {};
}
request = request || {};
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);
}
// --------------------
// -- Path templates --
// --------------------
/**
* Return a fully-qualified location resource name string.
*
* @param {String} project
* @param {String} location
* @returns {String}
*/
locationPath(project, location) {
return this._pathTemplates.locationPathTemplate.render({
project: project,
location: location,
});
}
/**
* Return a fully-qualified project resource name string.
*
* @param {String} project
* @returns {String}
*/
projectPath(project) {
return this._pathTemplates.projectPathTemplate.render({
project: project,
});
}
/**
* Return a fully-qualified queue resource name string.
*
* @param {String} project
* @param {String} location
* @param {String} queue
* @returns {String}
*/
queuePath(project, location, queue) {
return this._pathTemplates.queuePathTemplate.render({
project: project,
location: location,
queue: queue,
});
}
/**
* Return a fully-qualified task resource name string.
*
* @param {String} project
* @param {String} location
* @param {String} queue
* @param {String} task
* @returns {String}
*/
taskPath(project, location, queue, task) {
return this._pathTemplates.taskPathTemplate.render({
project: project,
location: location,
queue: queue,
task: task,
});
}
/**
* Parse the locationName from a location resource.
*
* @param {String} locationName
* A fully-qualified path representing a location resources.
* @returns {String} - A string representing the project.
*/
matchProjectFromLocationName(locationName) {
return this._pathTemplates.locationPathTemplate.match(locationName).project;
}
/**
* Parse the locationName from a location resource.
*
* @param {String} locationName
* A fully-qualified path representing a location resources.
* @returns {String} - A string representing the location.
*/
matchLocationFromLocationName(locationName) {
return this._pathTemplates.locationPathTemplate.match(locationName)
.location;
}
/**
* Parse the projectName from a project resource.
*
* @param {String} projectName
* A fully-qualified path representing a project resources.
* @returns {String} - A string representing the project.
*/
matchProjectFromProjectName(projectName) {
return this._pathTemplates.projectPathTemplate.match(projectName).project;
}
/**
* Parse the queueName from a queue resource.
*
* @param {String} queueName
* A fully-qualified path representing a queue resources.
* @returns {String} - A string representing the project.
*/
matchProjectFromQueueName(queueName) {
return this._pathTemplates.queuePathTemplate.match(queueName).project;
}
/**
* Parse the queueName from a queue resource.
*
* @param {String} queueName
* A fully-qualified path representing a queue resources.
* @returns {String} - A string representing the location.
*/
matchLocationFromQueueName(queueName) {
return this._pathTemplates.queuePathTemplate.match(queueName).location;
}
/**
* Parse the queueName from a queue resource.
*
* @param {String} queueName
* A fully-qualified path representing a queue resources.
* @returns {String} - A string representing the queue.
*/
matchQueueFromQueueName(queueName) {
return this._pathTemplates.queuePathTemplate.match(queueName).queue;
}
/**
* Parse the taskName from a task resource.
*
* @param {String} taskName
* A fully-qualified path representing a task resources.
* @returns {String} - A string representing the project.
*/
matchProjectFromTaskName(taskName) {
return this._pathTemplates.taskPathTemplate.match(taskName).project;
}
/**
* Parse the taskName from a task resource.
*
* @param {String} taskName
* A fully-qualified path representing a task resources.
* @returns {String} - A string representing the location.
*/
matchLocationFromTaskName(taskName) {
return this._pathTemplates.taskPathTemplate.match(taskName).location;
}
/**
* Parse the taskName from a task resource.
*
* @param {String} taskName
* A fully-qualified path representing a task resources.
* @returns {String} - A string representing the queue.
*/
matchQueueFromTaskName(taskName) {
return this._pathTemplates.taskPathTemplate.match(taskName).queue;
}
/**
* Parse the taskName from a task resource.
*
* @param {String} taskName
* A fully-qualified path representing a task resources.
* @returns {String} - A string representing the task.
*/
matchTaskFromTaskName(taskName) {
return this._pathTemplates.taskPathTemplate.match(taskName).task;
}
}
module.exports = CloudTasksClient;