Skip to content

Commit 0309078

Browse files
committed
make runner intervals configurable
1 parent 1b35d6b commit 0309078

File tree

5 files changed

+47
-18
lines changed

5 files changed

+47
-18
lines changed

apps/supervisor/src/env.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ const Env = z.object({
3030
TRIGGER_WORKLOAD_API_PORT_INTERNAL: z.coerce.number().default(8020), // This is the port the workload API listens on
3131
TRIGGER_WORKLOAD_API_PORT_EXTERNAL: z.coerce.number().default(8020), // This is the exposed port passed to the run controller
3232

33+
// Runner settings
34+
RUNNER_HEARTBEAT_INTERVAL_SECONDS: z.coerce.number().optional(),
35+
RUNNER_SNAPSHOT_POLL_INTERVAL_SECONDS: z.coerce.number().optional(),
36+
3337
// Dequeue settings (provider mode)
3438
TRIGGER_DEQUEUE_ENABLED: BoolEnv.default("true"),
3539
TRIGGER_DEQUEUE_INTERVAL_MS: z.coerce.number().int().default(1000),

apps/supervisor/src/index.ts

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { SupervisorSession } from "@trigger.dev/core/v3/workers";
22
import { SimpleStructuredLogger } from "@trigger.dev/core/v3/utils/structuredLogger";
33
import { env } from "./env.js";
44
import { WorkloadServer } from "./workloadServer/index.js";
5-
import { type WorkloadManager } from "./workloadManager/types.js";
5+
import type { WorkloadManagerOptions, WorkloadManager } from "./workloadManager/types.js";
66
import Docker from "dockerode";
77
import { z } from "zod";
88
import { type DequeuedMessage } from "@trigger.dev/core/v3";
@@ -50,16 +50,22 @@ class ManagedSupervisor {
5050
console.debug("[ManagedSupervisor] Starting up", { envWithoutSecrets });
5151
}
5252

53-
const workloadApiProtocol = env.TRIGGER_WORKLOAD_API_PROTOCOL;
54-
const workloadApiDomain = env.TRIGGER_WORKLOAD_API_DOMAIN;
55-
const workloadApiPortExternal = env.TRIGGER_WORKLOAD_API_PORT_EXTERNAL;
56-
5753
if (this.warmStartUrl) {
5854
this.logger.log("[ManagedWorker] 🔥 Warm starts enabled", {
5955
warmStartUrl: this.warmStartUrl,
6056
});
6157
}
6258

59+
const workloadManagerOptions = {
60+
workloadApiProtocol: env.TRIGGER_WORKLOAD_API_PROTOCOL,
61+
workloadApiDomain: env.TRIGGER_WORKLOAD_API_DOMAIN,
62+
workloadApiPort: env.TRIGGER_WORKLOAD_API_PORT_EXTERNAL,
63+
warmStartUrl: this.warmStartUrl,
64+
imagePullSecrets: env.KUBERNETES_IMAGE_PULL_SECRETS?.split(","),
65+
heartbeatIntervalSeconds: env.RUNNER_HEARTBEAT_INTERVAL_SECONDS,
66+
snapshotPollIntervalSeconds: env.RUNNER_SNAPSHOT_POLL_INTERVAL_SECONDS,
67+
} satisfies WorkloadManagerOptions;
68+
6369
if (this.isKubernetes) {
6470
if (env.POD_CLEANER_ENABLED) {
6571
this.logger.log("[ManagedWorker] 🧹 Pod cleaner enabled", {
@@ -92,21 +98,10 @@ class ManagedSupervisor {
9298
}
9399

94100
this.resourceMonitor = new KubernetesResourceMonitor(createK8sApi(), "");
95-
this.workloadManager = new KubernetesWorkloadManager({
96-
workloadApiProtocol,
97-
workloadApiDomain,
98-
workloadApiPort: workloadApiPortExternal,
99-
warmStartUrl: this.warmStartUrl,
100-
imagePullSecrets: env.KUBERNETES_IMAGE_PULL_SECRETS?.split(","),
101-
});
101+
this.workloadManager = new KubernetesWorkloadManager(workloadManagerOptions);
102102
} else {
103103
this.resourceMonitor = new DockerResourceMonitor(new Docker());
104-
this.workloadManager = new DockerWorkloadManager({
105-
workloadApiProtocol,
106-
workloadApiDomain,
107-
workloadApiPort: workloadApiPortExternal,
108-
warmStartUrl: this.warmStartUrl,
109-
});
104+
this.workloadManager = new DockerWorkloadManager(workloadManagerOptions);
110105
}
111106

112107
this.workerSession = new SupervisorSession({

apps/supervisor/src/workloadManager/docker.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@ export class DockerWorkloadManager implements WorkloadManager {
4545
runArgs.push(`--env=TRIGGER_WARM_START_URL=${this.opts.warmStartUrl}`);
4646
}
4747

48+
if (this.opts.heartbeatIntervalSeconds) {
49+
runArgs.push(
50+
`--env=TRIGGER_HEARTBEAT_INTERVAL_SECONDS=${this.opts.heartbeatIntervalSeconds}`
51+
);
52+
}
53+
54+
if (this.opts.snapshotPollIntervalSeconds) {
55+
runArgs.push(
56+
`--env=TRIGGER_SNAPSHOT_POLL_INTERVAL_SECONDS=${this.opts.snapshotPollIntervalSeconds}`
57+
);
58+
}
59+
4860
if (env.ENFORCE_MACHINE_PRESETS) {
4961
runArgs.push(`--cpus=${opts.machine.cpu}`, `--memory=${opts.machine.memory}G`);
5062
runArgs.push(`--env=TRIGGER_MACHINE_CPU=${opts.machine.cpu}`);

apps/supervisor/src/workloadManager/kubernetes.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,22 @@ export class KubernetesWorkloadManager implements WorkloadManager {
134134
...(this.opts.warmStartUrl
135135
? [{ name: "TRIGGER_WARM_START_URL", value: this.opts.warmStartUrl }]
136136
: []),
137+
...(this.opts.heartbeatIntervalSeconds
138+
? [
139+
{
140+
name: "TRIGGER_HEARTBEAT_INTERVAL_SECONDS",
141+
value: `${this.opts.heartbeatIntervalSeconds}`,
142+
},
143+
]
144+
: []),
145+
...(this.opts.snapshotPollIntervalSeconds
146+
? [
147+
{
148+
name: "TRIGGER_SNAPSHOT_POLL_INTERVAL_SECONDS",
149+
value: `${this.opts.snapshotPollIntervalSeconds}`,
150+
},
151+
]
152+
: []),
137153
],
138154
},
139155
],

apps/supervisor/src/workloadManager/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ export interface WorkloadManagerOptions {
66
workloadApiPort: number;
77
warmStartUrl?: string;
88
imagePullSecrets?: string[];
9+
heartbeatIntervalSeconds?: number;
10+
snapshotPollIntervalSeconds?: number;
911
}
1012

1113
export interface WorkloadManager {

0 commit comments

Comments
 (0)