Skip to content

Commit e93a105

Browse files
committed
refactor(trigger): run the per-attempt setup through one module
The init hook loads app modules by relative path, which the source-convention ratchet caps. Warming Redis and refreshing workload-identity credentials now sit behind prepareTriggerAttempt, so init still imports one module.
1 parent d999ce2 commit e93a105

2 files changed

Lines changed: 17 additions & 9 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { refreshAwsCredentialsForRun } from '@/lib/core/config/aws'
2+
import { warmRedisConnection } from '@/lib/core/config/redis'
3+
4+
/**
5+
* The per-attempt setup the Trigger.dev `init` hook awaits before `run()`. Warms the shared Redis
6+
* connection, and refreshes workload-identity AWS credentials while the attempt is executing and a
7+
* token can still be minted, so work a run leaves behind (the hosted-key metrics flush) has
8+
* credentials after the attempt ends. Never throws, like each step: a throw in `init` fails the
9+
* attempt.
10+
*/
11+
export async function prepareTriggerAttempt(): Promise<void> {
12+
await Promise.all([warmRedisConnection(), refreshAwsCredentialsForRun()])
13+
}

‎apps/sim/trigger.config.ts‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,8 @@ export default defineConfig({
160160
* because a throw here fails the run. The execution-signal subscriber is
161161
* deliberately not warmed here: only the tasks that execute a workflow ever
162162
* subscribe, and they are a minority of runs, so that connection is warmed
163-
* on intent at the execution entry point instead.
164-
*
165-
* Also refreshes workload-identity AWS credentials, alongside the Redis
166-
* warm-up, while the attempt is executing and a token can still be minted,
167-
* so work a run leaves behind (the hosted-key metrics flush) has credentials
168-
* after the attempt ends. Never throws, like the warm-up.
163+
* on intent at the execution entry point instead. The same step refreshes
164+
* workload-identity AWS credentials (`prepareTriggerAttempt`).
169165
*
170166
* @see https://trigger.dev/docs/config/config-file#lifecycle-functions
171167
*/
@@ -177,9 +173,8 @@ export default defineConfig({
177173
markInsideTriggerRun()
178174
const { reportAccountTokenSealing } = await import('@sim/db/sealed-text')
179175
reportAccountTokenSealing()
180-
const { warmRedisConnection } = await import('./lib/core/config/redis')
181-
const { refreshAwsCredentialsForRun } = await import('./lib/core/config/aws')
182-
await Promise.all([warmRedisConnection(), refreshAwsCredentialsForRun()])
176+
const { prepareTriggerAttempt } = await import('./lib/core/config/trigger-attempt')
177+
await prepareTriggerAttempt()
183178
},
184179
...(grafanaTelemetry ? { telemetry: grafanaTelemetry } : {}),
185180
build: {

0 commit comments

Comments
 (0)