Skip to content

Commit

Permalink
Add timeouts to function configuration (#733)
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 run will be cancelled.

- [x] Added a [docs PR](https://github.com/inngest/website) that
references this PR
- [x] Added unit/integration tests
- [x] Added changesets if applicable

---------

Co-authored-by: Jack Williams <[email protected]>
  • Loading branch information
tonyhb and jpwilliams authored Oct 29, 2024
1 parent 5b4c56f commit 96f5965
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/proud-pets-stare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"inngest": minor
---

Add timeouts as function config
35 changes: 35 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,39 @@ 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
12 changes: 12 additions & 0 deletions packages/inngest/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1169,6 +1169,18 @@ export const functionConfigSchema = z.strictObject({
.optional(),
})
.optional(),
timeouts: z
.strictObject({
start: z
.string()
.transform((x) => x as TimeStr)
.optional(),
finish: z
.string()
.transform((x) => x as TimeStr)
.optional(),
})
.optional(),
priority: z
.strictObject({
run: z.string().optional(),
Expand Down

0 comments on commit 96f5965

Please sign in to comment.