You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This release also includes a new experimental `processKeepAlive` option, which allows you to
1057
+
keep the process alive after the run has completed for the next warm start, which makes warm starts even faster.
1058
+
1059
+
Currently during a warm start, we still recreate the actual task run process between runs, leading to a completely fresh global environment for each run. This experimental option will keep the task run process alive between run executions, leading to even faster warm starts. This option is respected in both the `dev` CLI and in deployed tasks.
1060
+
1061
+
To enable this option, add this to your `trigger.config.ts`:
1062
+
1063
+
```ts
1064
+
import { defineConfig } from"@trigger.dev/sdk";
1065
+
1066
+
exportdefaultdefineConfig({
1067
+
project: "<project ref>",
1068
+
// This is false by default
1069
+
experimental_processKeepAlive: true,
1070
+
maxDuration: 60,
1071
+
});
1072
+
```
1073
+
1074
+
You can also pass an object to `experimental_processKeepAlive` to provide more options:
1075
+
1076
+
```ts
1077
+
import { defineConfig } from"@trigger.dev/sdk";
1078
+
1079
+
exportdefaultdefineConfig({
1080
+
project: "<project ref>",
1081
+
experimental_processKeepAlive: {
1082
+
enabled: true,
1083
+
// After 20 runs execute with a single process, we'll restart the process and start fresh
1084
+
maxExecutionsPerProcess: 20,
1085
+
// In dev, you can combine this option with setting a max pool size, giving you the ability to limit the number of processes created on your local dev machine. Has no effect on deployed tasks
1086
+
devMaxPoolSize: 10,
1087
+
},
1088
+
maxDuration: 60,
1089
+
});
1090
+
```
1091
+
1092
+
## Gotchas
1093
+
1094
+
- Be careful with memory usage and memory leaks, as this will cause memory to persist across run executions.
1095
+
- It's possible different tasks get executed in the same persisted process.
1096
+
- If you configure any 3rd party SDKs globally using env vars for API keys, those SDKs will not change between runs. So if you change an env var between runs, the SDK will be "stale" and continue using the old env var value. Instead, you should initialize SDKs using env vars at runtime (in any of the lifecycle hooks or inside the `run` function of a task.
1097
+
- Cancelling a task will cause the task run process to be restarted. Exiting the process is the only reliable way to actually stop a running function from stopping.
1098
+
- This DOES NOT effect cold starts, warm starts only will be improved.
1099
+
1100
+
We recommend enabling this option and testing in a staging or preview environment before trying it out in prod, as there could be unknown issues depending on what you are doing in your tasks. [#2183](https://github.com/triggerdotdev/trigger.dev/pull/2183)
0 commit comments