This package has been deprecated

Author message:

WARNING: This project has been renamed to @mondomob/gae-js-tasks. Please install using the new package.

@dotrun/gae-js-tasks
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

GAE JS TASKS

Use Cloud Tasks to call task handler endpoints in your app.

Installation

npm install @dotrun/gae-js-tasks

Components

TaskQueueService

Helper service for enqueuing tasks.

This uses the convention that tasks will be handled by a POST route of the current application, with a configured path prefix (default /tasks) and path name equal to that of the task name. e.g. for a task name of poll-status the target URI of the enqueued task will be POST /tasks/poll-status

When deployed to GCP will enqueue to a real task queue (default queue of default). Locally will immediately invoke the target URI.

// Create new service instance
const taskService = new TaskQueueService({queueName: "default"});

// Enqueue a task on queue `default` to call endpoint `/tasks/poll-status` with provided payload
await taskService.enqueue("poll-status", {jobId: "1234"});

gaeJsTask Middleware

A convenience middleware collection for your task endpoints to:

a) verify the request is a genuine Cloud Tasks request (see verifyTask middleware) and b) extend the NodeJS request timeout to 10 minutes (the default is 120s)

// Apply middleware however you normally would
app.use("/tasks", gaeJsTask);

// Now any matching routes will be protected and timeout extended
app.post("/tasks/start-job", (req, res) => res.send("OK"));
app.post("/tasks/poll-status", (req, res) => res.send("OK"));

verifyTask Middleware

Use this on your task handlers to ensure they are only called by genuine Cloud Tasks requests. NOTE: This is already part of the gaeJsTask middleware so no need to apply again if using that.

// Apply middleware however you normally would
app.use("/tasks", verifyTask);

// Now any matching routes will be protected
app.post("/tasks/start-job", (req, res) => res.send("OK"));
app.post("/tasks/poll-status", (req, res) => res.send("OK"));

Readme

Keywords

none

Package Sidebar

Install

npm i @dotrun/gae-js-tasks

Weekly Downloads

1

Version

1.0.1

License

MIT

Unpacked Size

17.7 kB

Total Files

29

Last publish

Collaborators

  • mlevett