Skip to content

Commit e9494d5

Browse files
Update @vercel/queue (#498)
1 parent 2f0840b commit e9494d5

File tree

4 files changed

+27
-27
lines changed

4 files changed

+27
-27
lines changed

.changeset/wet-roses-happen.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@workflow/world-vercel": patch
3+
---
4+
5+
Update `@vercel/queue` to use new QueueClient class to simplify custom header/path overwrites

packages/world-vercel/src/queue.ts

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { handleCallback, send } from '@vercel/queue';
1+
import { Client } from '@vercel/queue';
22
import {
33
MessageId,
44
type Queue,
@@ -18,21 +18,12 @@ const VERCEL_QUEUE_MAX_VISIBILITY = 82800; // 23 hours in seconds
1818
export function createQueue(config?: APIConfig): Queue {
1919
const { baseUrl, usingProxy } = getHttpUrl(config);
2020
const headers = getHeaders(config);
21-
if (usingProxy) {
22-
// If we're using a proxy for the Workflow API, we should also go
23-
// through the proxy for the queues API.
24-
process.env.VERCEL_QUEUE_BASE_URL = `${baseUrl}`;
25-
process.env.VERCEL_QUEUE_BASE_PATH = '/queues/v2/messages';
26-
if (config?.token) {
27-
process.env.VERCEL_QUEUE_TOKEN = config.token;
28-
}
29-
if (headers) {
30-
headers.forEach((value, key) => {
31-
const sanitizedKey = key.replaceAll('-', '__');
32-
process.env[`VERCEL_QUEUE_HEADER_${sanitizedKey}`] = value;
33-
});
34-
}
35-
}
21+
const queueClient = new Client({
22+
baseUrl: usingProxy ? baseUrl : undefined,
23+
basePath: usingProxy ? '/queues/v2/messages' : undefined,
24+
token: usingProxy ? config?.token : undefined,
25+
headers: Object.fromEntries(headers.entries()),
26+
});
3627

3728
const queue: Queue['queue'] = async (queueName, x, opts) => {
3829
// zod v3 doesn't have the `encode` method. We only support zod v4 officially,
@@ -51,12 +42,16 @@ export function createQueue(config?: APIConfig): Queue {
5142
queueName,
5243
});
5344
const sanitizedQueueName = queueName.replace(/[^A-Za-z0-9-_]/g, '-');
54-
const { messageId } = await send(sanitizedQueueName, encoded, opts);
45+
const { messageId } = await queueClient.send(
46+
sanitizedQueueName,
47+
encoded,
48+
opts
49+
);
5550
return { messageId: MessageId.parse(messageId) };
5651
};
5752

5853
const createQueueHandler: Queue['createQueueHandler'] = (prefix, handler) => {
59-
return handleCallback({
54+
return queueClient.handleCallback({
6055
[`${prefix}*`]: {
6156
default: async (body, meta) => {
6257
const { payload, queueName } = MessageWrapper.parse(body);

pnpm-lock.yaml

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ catalog:
1010
"@types/node": 22.19.0
1111
"@vercel/functions": ^3.1.4
1212
"@vercel/oidc": 3.0.5
13-
"@vercel/queue": 0.0.0-alpha.29
13+
"@vercel/queue": 0.0.0-alpha.33
1414
"@vitest/coverage-v8": ^3.2.4
1515
ai: 5.0.104
1616
esbuild: ^0.25.11

0 commit comments

Comments
 (0)