@lunora/queue 1.0.0-alpha.1 → 1.0.0-alpha.100

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.md CHANGED
@@ -103,3 +103,9 @@ Unless required by applicable law or agreed to in writing, software distributed
103
103
  under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
104
104
  CONDITIONS OF ANY KIND, either express or implied. See the License for the
105
105
  specific language governing permissions and limitations under the License.
106
+
107
+ <!-- DEPENDENCIES -->
108
+ <!-- /DEPENDENCIES -->
109
+
110
+ <!-- TYPE_DEPENDENCIES -->
111
+ <!-- /TYPE_DEPENDENCIES -->
package/README.md CHANGED
@@ -26,18 +26,36 @@ import { api } from "./_generated/api";
26
26
  export const emailQueue = defineQueue<{ to: string }>({
27
27
  handler: async (ctx, batch) => {
28
28
  for (const message of batch.messages) {
29
- await ctx.run(api.email.send, { to: message.body.to });
29
+ await message.run(api.email.send, { to: message.body.to });
30
30
  message.ack();
31
31
  }
32
32
  },
33
33
  });
34
34
  ```
35
35
 
36
+ `message.run(...)` is `ctx.run(...)` pinned to that message. Call it inside the
37
+ batch loop: when the dispatched function fails deterministically (`400`, `403`,
38
+ `404`, `422`), the consumer acks just that message and retries the rest instead
39
+ of letting one poison message retry — and eventually dead-letter — the whole
40
+ batch.
41
+
36
42
  ```ts
37
43
  // inside a mutation/action
38
44
  await ctx.queues.emailQueue.send({ to: user.email });
39
45
  ```
40
46
 
47
+ For one event with several consumers, declare a topic and subscribe to it.
48
+ Each subscription is its own queue, with its own retries and dead-letter queue:
49
+
50
+ ```ts
51
+ // lunora/queues.ts
52
+ export const signups = defineTopic<{ userId: string }>();
53
+ export const welcomeEmail = defineSubscription(signups, { handler: async (ctx, batch) => {} });
54
+
55
+ // inside a mutation/action
56
+ await ctx.topics.signups.publish({ userId });
57
+ ```
58
+
41
59
  Codegen emits the typed `ctx.queues` producer and the worker `queue()` dispatch;
42
60
  `@lunora/config` reconciles the wrangler `queues.producers[]` /
43
61
  `queues.consumers[]` entries from the same definition. Scaffold a new queue with