This package helps with utils that are not offered by @google-cloud/tasks
npm install cloud-task-wrapperbash
npm i cloud-task-wrapper
`
$3
`javascript
// Imports the Google Cloud Tasks Wrapper library.
const { CloudTaskWrapper } = require("cloud-task-wrapper");
async function quickstart() {
// TODO(developer): Uncomment these lines and replace with your values.
// const project = 'my-project-id';
// const queue = 'my-appengine-queue';
// const location = 'us-central1';
const config = {
project,
location,
};
const wrapper = new CloudTaskWrapper(config);
const cloudTasks = await wrapper.getCloudTasksByRegex(regex, queue); //regex that matches name of your cloud task
console.log(List of matching cloud tasks ${cloudTasks});
}
quickstart();
`
$3
`javascript
// Imports the Google Cloud Tasks Wrapper library.
const { CloudTaskWrapper } = require("cloud-task-wrapper");
async function quickstart() {
// TODO(developer): Uncomment these lines and replace with your values.
// const project = 'my-project-id';
// const queue = 'my-appengine-queue';
// const location = 'us-central1';
const config = {
project,
location,
};
const wrapper = new CloudTaskWrapper(config);
const cloudTasks = await wrapper.getCloudTasksByRegex(regex, queue); //regex that matches name of your cloud task
for (const cloudTask of cloudTasks) {
const taskName = cloudTask.name.split("/").pop();
await wrapper.deleteCloudTaskByName(taskName, queue);
}
console.log(List of deleted cloud tasks ${cloudTasks});
}
quickstart();
`
$3
`javascript
// Imports the Google Cloud Tasks Wrapper library.
const { CloudTaskWrapper } = require("cloud-task-wrapper");
async function quickstart() {
// TODO(developer): Uncomment these lines and replace with your values.
// const project = 'my-project-id';
// const queue = 'my-appengine-queue';
// const location = 'us-central1';
const config = {
project,
location,
};
const wrapper = new CloudTaskWrapper(config);
//TODO: Uncomment these lines and replace with values name of the cloud task to be updated, time in minutes to be triggered (UTC), new Name is optional
//const name = 'cloud task name';
//const inMinutes = 20
//const newName = 'This is optional';
const updatedCloudTask = await wrapper.updateCloudTaskScheduledTime(
name,
20,
queue,
newName
);
console.log(Updated the cloud task and its new name - ${updatedCloudTask});
}
quickstart();
`
$3
`javascript
// Imports the Google Cloud Tasks Wrapper library.
const { CloudTaskWrapper } = require("cloud-task-wrapper");
async function quickstart() {
// TODO(developer): Uncomment these lines and replace with your values.
// const project = 'my-project-id';
// const queue = 'my-appengine-queue';
// const location = 'us-central1';
const config = {
project,
location,
};
const wrapper = new CloudTaskWrapper(config);
const cloudTask = await wrapper.getCloudTaskByName(name, queue); //just the name of cloud task eg: 133454565656767
console.log(The cloud task is - ${cloudTask});
}
quickstart();
`
$3
`javascript
// Imports the Google Cloud Tasks Wrapper library.
const { CloudTaskWrapper } = require("cloud-task-wrapper");
async function quickstart() {
// TODO(developer): Uncomment these lines and replace with your values.
// const project = 'my-project-id';
// const queue = 'my-appengine-queue';
// const location = 'us-central1';
const config = {
project,
location,
};
const wrapper = new CloudTaskWrapper(config);
await wrapper.deleteCloudTaskByName(name, queue); //just the name of cloud task eg: 133454565656767
console.log(Deleted the cloud task);
}
quickstart();
`
$3
`javascript
const { CloudTaskWrapper } = require("cloud-task-wrapper");
async function quickstart() {
// TODO(developer): Uncomment these lines and replace with your values.
// const project = 'my-project-id';
// const queue = 'my-appengine-queue';
// const location = 'us-central1';
// const payload = 'hello';
const config = {
project,
queue,
location,
};
const wrapper = new CloudTaskWrapper(config);
const task = {
appEngineHttpRequest: {
httpMethod: "POST",
relativeUri: "/log_payload",
body: Buffer.from(payload).toString("base64")
},
scheduleTime = {
seconds: inSeconds + Date.now() / 1000, //inSeconds is the time for the task to be executed
};
};
// Send create task request.
const cloudTask = await wrapper.createCloudTask(task, queue, name); //name of cloud task is optional
console.log(Created task ${cloudTask});
}
quickstart();
`
$3
`javascript
const { CloudTaskWrapper } = require("cloud-task-wrapper");
async function quickstart() {
// TODO(developer): Uncomment these lines and replace with your values.
// const project = 'my-project-id';
// const queue = 'my-appengine-queue';
// const location = 'us-central1';
// const payload = 'hello';
const config = {
project,
location,
};
const wrapper = new CloudTaskWrapper(config);
const task = {
httpRequest: {
httpMethod: "POST",
url: "https://ram-sankhavaram.com",
body: Buffer.from(payload).toString("base64"),
},
scheduleTime = {
seconds: inSeconds + Date.now() / 1000, //inSeconds is the time for the task to be executed
};
};
// Send create task request.
const cloudTask = await wrapper.createCloudTask(task, queue, name); //name of cloud task is optional
console.log(Created task ${cloudTask});
}
quickstart();
``