Skip to content

@requence/task

The @requence/task package can be used to create and monitor tasks in real time. Additionally, type declarations can be generated using the provided CLI tool requence-task.

Terminal window
npm install @requence/task@next

The task package requires an access token to communicate with the Requence servers. For development and type generation, a personal access token is needed. For production use, an organization, group, or project access token can be used instead.

A personal access token can be generated via the settings in your user space.

personal access token

A scoped access token can be generated via the settings of an organization, a group or a project

scoped access token

As with the @requence/service package, the access token in the task package can be used in multiple ways.

Terminal window
REQUENCE_TASK_ACCESS_TOKEN="..."
# or
REQUENCE_ACCESS_TOKEN="..."
{
"name": "...",
"type": "module",
"version": "...",
"dependencies": {
"@requence/task": "next"
}
"peerDependencies": {
"typescript": "^5.0.0",
},
"requence": {
"accessToken": "..."
}
}
import { createTask } from '@requence/task'
createTask(
{
accessToken: '...',
...
}
)

Just like the @package/service package, the @package/task package comes with its own CLI tool. This tool can be used to generate the corresponding TypeScript types.

Terminal window
requence-task generate-types
# alternative with explicite access token
requence-task generate-types --access-token=...

This (as with @package/service) generates a requence-env.d.ts file that includes the types of all tasks that can be executed using your personal access token.

A task can be created by calling the createTask function. This requires specifying a task template (either by uuid or, way more convenient, by slug). Depending on the template, different values for input and meta are required.

import { createTask } from '@requence/task'
createTask(
{
taskTemplate: 'my-task-template',
input: ...
meta: ...
}
)

There are several ways to obtain the result of a task. The simplest way is to await the execution of createTask.

import { createTask } from '@requence/task'
const result = await createTask(
{
taskTemplate: 'my-task-template',
input: ...
meta: ...
}
)
console.log(result.getData())

TBD