Skip to content

flowControl period parameter does not work with publishJSON #240

Description

@Pankkss

Problem

When using the period parameter in the publishJSON function, I get the following error:

Error processing webhook: Error [QstashError]: {"error":"Upstash-Flow-Control-Value should be either rate=X or parallelism=Y, or both as comma-separated values"}
    at async queueSingleEvent (lib/queue/qstash.ts:74:25)
    at async POST (app/api/public/webhooks/stripe/route.ts:45:16)
  72 |         }
  73 |         console.log('params', params);
> 74 |         const response = await getClient().publishJSON({
     |                         ^
  75 |             url: `${process.env.NEXT_PUBLIC_APP_URL}/api/public/webhooks/${url}`,
  76 |             headers: {
  77 |                 ...headers, {
  status: 400
}

The code block below works as long as I don't include the period parameter. I've tried the period parameter with both a number and string like "1s". Neither works.

Code block

        const response = await getClient().publishJSON({
            url: `${process.env.NEXT_PUBLIC_APP_URL}/api/public/webhooks/${url}`,
            headers: {
                ...headers,
            },
            messageId: message_id,
            flowControl: {
                key: QUEUE_TWILIO,
                rate: isDev() ? 1 : 3,
                parallelism: 3,
                period: "1s",
            },
            notBefore: isDev() ? 0 : Math.floor(delivery_date!.getTime() / 1000),
            body: {
                event: event,
                message_id: message_id,
                isDev: isDev(),
            }
        });

I assume this implementation should work as it's structure is similar to (these docs)[https://upstash.com/docs/qstash/features/flowcontrol], specifically this example:

const client = new Client({ token: "<QSTASH_TOKEN>" });

await client.publishJSON({
    url: "https://example.com",
    body: { hello: "world" },
    flowControl: { key: "USER_GIVEN_KEY", rate: 10, parallelism: 20, period: "1m" },
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions