Skip to content

Commit

Permalink
Add timeouts to function configuration
Browse files Browse the repository at this point in the history
This adds to parameters:

- `timeouts.start`
- `timeouts.finish`

If either of these timeouts are hit, the function will be cancelled.
  • Loading branch information
tonyhb committed Oct 28, 2024
1 parent 5b4c56f commit e3a13b9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
33 changes: 33 additions & 0 deletions packages/inngest/src/components/InngestFunction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export class InngestFunction<
throttle,
concurrency,
debounce,
timeouts,
priority,
} = this.opts;

Expand Down Expand Up @@ -165,6 +166,7 @@ export class InngestFunction<
concurrency,
debounce,
priority,
timeouts,
};

if (cancelOn) {
Expand Down Expand Up @@ -480,6 +482,37 @@ export namespace InngestFunction {
run?: string;
};

/**
* Configure timeouts for the function. If any of the timeouts are hit, the
* function run will be cancelled.
*/
timeouts?: {
/**
* Start represents the timeout for starting a function. If the time
* between scheduling and starting a function exceeds this value, the
* function will be cancelled.
*
* This is, essentially, the amount of time that a function sits in the
* queue before starting.
*
* A function may exceed this duration because of concurrency limits,
* throttling, etc.
*/
start?: TimeStr;

/**
* Finish represents the time between a function starting and the function finishing.
* If a function takes longer than this time to finish, the function is marked as cancelled.
*
* The start time is taken from the time that the first successful function request begins,
* and does not include the time spent in the queue before the function starts.
*
* Note that if the final request to a function begins before this timeout, and completes
* after this timeout, the function will succeed.
*/
finish?: TimeStr;
},

cancelOn?: Cancellation<GetEvents<TClient, true>>[];

/**
Expand Down
6 changes: 6 additions & 0 deletions packages/inngest/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1169,6 +1169,12 @@ export const functionConfigSchema = z.strictObject({
.optional(),
})
.optional(),
timeouts: z
.strictObject({
start: z.string().transform((x) => x as TimeStr),
finish: z.string().transform((x) => x as TimeStr),
})
.optional(),
priority: z
.strictObject({
run: z.string().optional(),
Expand Down

0 comments on commit e3a13b9

Please sign in to comment.