-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsyncDopplerEnvVars.ts
More file actions
34 lines (29 loc) · 1.35 KB
/
Copy pathsyncDopplerEnvVars.ts
File metadata and controls
34 lines (29 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { envvars, logger, task } from "@trigger.dev/sdk";
import { fetchSyncableDopplerSecrets } from "../doppler/sync";
/**
* The webhook-driven way of syncing Doppler secrets into Trigger.dev.
*
* It takes no payload: it downloads and syncs ALL syncable env vars for its own
* environment, exactly like the `syncDopplerEnvVars` build extension does at
* deploy time (both share {@link fetchSyncableDopplerSecrets}).
*
* `concurrencyLimit: 1` means only one sync ever runs at a time. Combined with
* the debounce on the trigger side (see the Next.js webhook route), a burst of
* Doppler webhooks collapses into a single sync of the latest state.
*/
export const syncDopplerEnvVarsTask = task({
id: "sync-doppler-env-vars",
queue: { concurrencyLimit: 1 },
run: async (_payload: void, { ctx }) => {
const environment = ctx.environment.slug;
const variables = await fetchSyncableDopplerSecrets(environment);
const names = Object.keys(variables);
if (names.length === 0) {
logger.warn("No syncable Doppler secrets found; nothing to sync", { environment });
return { environment, synced: 0 };
}
await envvars.upload({ variables, override: true, isSecret: true });
logger.info("Synced Doppler secrets into Trigger.dev", { environment, count: names.length });
return { environment, synced: names.length, keys: names };
},
});