Simplify batch options
This commit is contained in:
@@ -8,7 +8,6 @@ import {
|
||||
} from "@trigger.dev/core";
|
||||
import type {
|
||||
Endpoint,
|
||||
EventDispatcher,
|
||||
Integration,
|
||||
Job,
|
||||
JobIntegration,
|
||||
@@ -421,13 +420,8 @@ export class RegisterJobService {
|
||||
batchOptions?: BatcherOptions
|
||||
) {
|
||||
if (batchOptions) {
|
||||
let maxPayloads: number | null = null;
|
||||
let maxInterval: number | null = null;
|
||||
|
||||
if (typeof batchOptions !== "boolean") {
|
||||
maxPayloads = batchOptions.maxPayloads ?? null;
|
||||
maxInterval = batchOptions.maxInterval ?? null;
|
||||
}
|
||||
const maxPayloads = batchOptions.maxPayloads ?? null;
|
||||
const maxInterval = batchOptions.maxInterval ?? null;
|
||||
|
||||
await tx.eventDispatchBatcher.upsert({
|
||||
where: {
|
||||
|
||||
@@ -184,13 +184,8 @@ export class RegisterWebhookService {
|
||||
batchOptions?: BatcherOptions
|
||||
) {
|
||||
if (batchOptions) {
|
||||
let maxPayloads: number | null = null;
|
||||
let maxInterval: number | null = null;
|
||||
|
||||
if (typeof batchOptions !== "boolean") {
|
||||
maxPayloads = batchOptions.maxPayloads ?? null;
|
||||
maxInterval = batchOptions.maxInterval ?? null;
|
||||
}
|
||||
const maxPayloads = batchOptions.maxPayloads ?? null;
|
||||
const maxInterval = batchOptions.maxInterval ?? null;
|
||||
|
||||
await tx.webhookDeliveryBatcher.upsert({
|
||||
where: {
|
||||
|
||||
@@ -37,13 +37,10 @@ export const TriggerHelpSchema = z.object({
|
||||
.optional(),
|
||||
});
|
||||
|
||||
export const BatcherOptionsSchema = z.union([
|
||||
z.boolean(),
|
||||
z.object({
|
||||
maxPayloads: z.number().optional(),
|
||||
maxInterval: z.number().optional(),
|
||||
}),
|
||||
]);
|
||||
export const BatcherOptionsSchema = z.object({
|
||||
maxPayloads: z.number().optional(),
|
||||
maxInterval: z.number().optional(),
|
||||
});
|
||||
|
||||
export type BatcherOptions = z.infer<typeof BatcherOptionsSchema>;
|
||||
|
||||
|
||||
@@ -49,14 +49,12 @@ export class EventTrigger<TEventSpecification extends EventSpecification<any>>
|
||||
|
||||
attachToJob(triggerClient: TriggerClient, job: Job<Trigger<TEventSpecification>, any>): void {}
|
||||
|
||||
batch(
|
||||
options?: Exclude<BatcherOptions, boolean>
|
||||
): EventTrigger<TEventSpecification> {
|
||||
batch(options?: BatcherOptions): EventTrigger<TEventSpecification> {
|
||||
const { batch, ...rest } = this.#options;
|
||||
|
||||
return new EventTrigger({
|
||||
...rest,
|
||||
batch: options ?? true,
|
||||
batch: options ?? {},
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -142,7 +142,7 @@ type WebhookOptions<
|
||||
crud: WebhookCRUD<TIntegration, TParams, TConfig>;
|
||||
filter?: FilterFunction<TParams, TConfig>;
|
||||
register?: RegisterFunction<TIntegration, TParams, TConfig>;
|
||||
batch?: Exclude<BatcherOptions, boolean>;
|
||||
batch?: BatcherOptions;
|
||||
verify?: (options: {
|
||||
request: Request;
|
||||
client: TriggerClient;
|
||||
@@ -307,14 +307,12 @@ export class WebhookTrigger<
|
||||
};
|
||||
}
|
||||
|
||||
batch(
|
||||
options?: Exclude<BatcherOptions, boolean>
|
||||
): WebhookTrigger<TEventSpecification, TEventSource> {
|
||||
batch(options?: BatcherOptions): WebhookTrigger<TEventSpecification, TEventSource> {
|
||||
const { batch, ...rest } = this.options;
|
||||
|
||||
return new WebhookTrigger({
|
||||
...rest,
|
||||
batch: options ?? true,
|
||||
batch: options ?? {},
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user