diff --git a/docs/integrations/apis/shopify-triggers.mdx b/docs/integrations/apis/shopify-triggers.mdx index 9e630dc2b..6911d7f42 100644 --- a/docs/integrations/apis/shopify-triggers.mdx +++ b/docs/integrations/apis/shopify-triggers.mdx @@ -12,25 +12,58 @@ You can use these triggers to start a job when a Shopify event occurs. All triggers can be create folllowing the same pattern: ```ts -shopify.on("topic") +shopify.on("topic"); ``` The webhook topic you want to subscribe to. Generally a pattern of `/`. -### Helpers +## Helpers + +### filter() The `filter()` method returns a new trigger with the applied payload filter: ```ts -const trigger = shopify.on("topic").filter(filter) +shopify.on("topic").filter(filter); ``` A filter to apply to the event. See our [EventFilter guide](/documentation/guides/event-filter). +### batch() + +The `batch()` method returns a new trigger with batching enabled. + +Batching will cause the `payload` parameter of the run function to become an array of payloads instead. + +```ts +shopify.on("topic").batch({ + // receive no more than 5 payloads per batch + maxPayloads: 5, + // send out incomplete batches after 10 seconds + maxInterval: 10, +}); + +// shortcut to enable with sensible defaults +shopify.on("topic").batch(); +``` + + + Used to configure batching options. An empty or absent object will enable batching with server defaults. + + + + How many event payloads you will at most receive per batch. May be reduced by server limits.. + + + How many seconds to wait before sending out incomplete batches. May be cut short by server limits. + + + + ## Events What follows is a small selection of webhook topics and associated payloads. A complete list of possible topic names and payloads can be found [here](https://shopify.dev/docs/api/admin-rest/2023-07/resources/webhook#event-topics). diff --git a/docs/sdk/eventtrigger.mdx b/docs/sdk/eventtrigger.mdx index 5c7b30c95..04861caf3 100644 --- a/docs/sdk/eventtrigger.mdx +++ b/docs/sdk/eventtrigger.mdx @@ -66,9 +66,51 @@ You can have multiple Jobs that subscribe to the same event, they will all trigg + + Used to configure batching options. An empty object will enable batching with server defaults. + + Batching will cause the `payload` parameter of the run function to become an array of payloads instead. + + + + How many event payloads you will at most receive per batch. May be reduced by server limits.. + + + How many seconds to wait before sending out incomplete batches. May be cut short by server limits. + + + + +## Batching + +Batching will cause the `payload` parameter of the run function to become an array of payloads instead. + +It can be enabled via the `batch` property or alternatively via the `batch()` method on existing triggers: + +```typescript +eventTrigger({ + name: "batch.this", + batch: { + // receive no more than 5 payloads per batch + maxPayloads: 5, + // send out incomplete batches after 10 seconds + maxInterval: 10, + } +}); + +// alternatively +eventTrigger({ name: "batch.this" }).batch({ + maxPayloads: 5, + maxInterval: 10, +}); + +// shortcut to enable with sensible defaults +eventTrigger({ name: "batch.this" }).batch(); +``` + ```typescript eventTrigger() diff --git a/packages/trigger-sdk/src/triggers/eventTrigger.ts b/packages/trigger-sdk/src/triggers/eventTrigger.ts index 16aadd03e..23774a134 100644 --- a/packages/trigger-sdk/src/triggers/eventTrigger.ts +++ b/packages/trigger-sdk/src/triggers/eventTrigger.ts @@ -63,9 +63,11 @@ export class EventTrigger< /** * Used to configure batching options. An empty object will enable batching with server defaults. * + * Batching will cause the `payload` parameter of the run function to become an array of payloads instead. + * * @param options - Is an object containing the following properties: - * @param {number} options.maxPayloads - The `maxPayloads` property defines how many event payloads you will receive at most per batch. This is affected by server limits, but you should never receive more than this. - * @param {number} options.maxInterval - The `maxInterval` property defines how many seconds to wait before sending out batches that aren't full yet. This is affected by server limits, but you should never receive more than this. + * @param {number} options.maxPayloads - The `maxPayloads` property defines How many event payloads you will at most receive per batch. May be reduced by server limits.. + * @param {number} options.maxInterval - The `maxInterval` property defines how many seconds to wait before sending out incomplete batches. May be cut short by server limits. */ batch(options?: BatcherOptions): EventTrigger { const { batch, ...rest } = this.#options; @@ -126,8 +128,10 @@ type TriggerOptions { const { batch, ...rest } = this.options;