Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kv.listenQueue should warn if called multiple times #28772

Open
roziscoding opened this issue Apr 6, 2025 · 0 comments
Open

kv.listenQueue should warn if called multiple times #28772

roziscoding opened this issue Apr 6, 2025 · 0 comments

Comments

@roziscoding
Copy link

roziscoding commented Apr 6, 2025

Although the docs don’t clearly state it (at least I couldn’t find it), the runtime doesn’t appear to support multiple listeners for the queue—or at least it doesn’t call all of them. This means it’s not safe to call listenQueue more than once, because you don’t know which listener will be used.

This observation came from the following code:

kv.listenQueue(async (event) => {
    if (!ProcessNotificationEvent.safeParse(event).success) return;

    await sendNotification(event.data);
});

kv.listenQueue(async (event) => {
    if (!DeleteSubscriptionEvent.safeParse(event).success) return;

    await deleteSubscription(event.data);
});

I usually have ~25 notification events enqueued at the same time, but not all of them were actually run—there were no error logs, and no undelivered messages. I then realized I was probably only supposed to call listenQueue once. So I moved the handlers to functions and called them inside a single listener:

kv.listenQueue(async (event) => {
    await processNotification(event);
    await deleteSubscription(event);
});

After that, all notifications were correctly delivered.

I don’t know if adding a warning or even throwing an error is feasible, but I believe this behavior could at least be documented more clearly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant