Next.js and Taskless

The Next.js integration is available via the npm package @taskless/next and follows the standard createQueue convention. The returned object is both a Taskless aware API as well as a NextAPIHandler and can be placed in the standard /pages/api/<queue-name> location.

1function createQueue<T>(
2 queueName: string,
3 path: string,
4 handler: JobHandler<T>,
5 queueOptions?: QueueOptions
6): TasklessNextApiHandler<T>;
8interface JobHandler<T> {
9 (payload: T, meta: JobMetadata): Promised<unknown>;
12interface TasklessNextApiHandler<T> extends NextApiHandler, QueueMethods<T> {
13 (request: NextApiRequest, response: NextApiResponse): void | Promise<void>;
14 withQueue: (wrappedHandler: NextApiHandler) => TasklessNextApiHandler<T>;

Next Specific Methods

withQueue(wrappedHandler: NextApiHandler): TasklessNextApiHandler When using integrations such as sentry for next.js, your next.js handler is wrapped in a manner that obscures the Taskless methods. When this happens, calls to the core methods such as enqueue will result in an error trying to call an undefined value. To work around this limitation, the Next.js integration exposes withQueue method, which will reattach the core methods to the provided NextApiHandler.