Skip to content
Prev Previous commit
Next Next commit
deterministic runner ids
  • Loading branch information
nicktrn committed Apr 4, 2025
commit c260a5ca37b4f5b1d42d758d0c38a0cf0ca623da
4 changes: 4 additions & 0 deletions apps/supervisor/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ export function getDockerHostDomain() {

return isMacOs || isWindows ? "host.docker.internal" : "localhost";
}

export function getRunnerId(runId: string) {
return `runner-${runId.replace("run_", "")}`;
}
6 changes: 3 additions & 3 deletions apps/supervisor/src/workloadManager/docker.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { SimpleStructuredLogger } from "@trigger.dev/core/v3/utils/structuredLogger";
import { RunnerId } from "@trigger.dev/core/v3/isomorphic";
import {
type WorkloadManager,
type WorkloadManagerCreateOptions,
type WorkloadManagerOptions,
} from "./types.js";
import { x } from "tinyexec";
import { env } from "../env.js";
import { getDockerHostDomain } from "../util.js";
import { getDockerHostDomain, getRunnerId } from "../util.js";

export class DockerWorkloadManager implements WorkloadManager {
private readonly logger = new SimpleStructuredLogger("docker-workload-provider");
Expand All @@ -23,7 +22,8 @@ export class DockerWorkloadManager implements WorkloadManager {
async create(opts: WorkloadManagerCreateOptions) {
this.logger.log("[DockerWorkloadProvider] Creating container", { opts });

const runnerId = RunnerId.generate();
const runnerId = getRunnerId(opts.runFriendlyId);

const runArgs = [
"run",
"--detach",
Expand Down
4 changes: 2 additions & 2 deletions apps/supervisor/src/workloadManager/kubernetes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import {
type WorkloadManagerCreateOptions,
type WorkloadManagerOptions,
} from "./types.js";
import { RunnerId } from "@trigger.dev/core/v3/isomorphic";
import type { EnvironmentType, MachinePreset } from "@trigger.dev/core/v3";
import { env } from "../env.js";
import { type K8sApi, createK8sApi, type k8s } from "../clients/kubernetes.js";
import { getRunnerId } from "../util.js";

type ResourceQuantities = {
[K in "cpu" | "memory" | "ephemeral-storage"]?: string;
Expand All @@ -31,7 +31,7 @@ export class KubernetesWorkloadManager implements WorkloadManager {
async create(opts: WorkloadManagerCreateOptions) {
this.logger.log("[KubernetesWorkloadManager] Creating container", { opts });

const runnerId = RunnerId.generate().replace(/_/g, "-");
const runnerId = getRunnerId(opts.runFriendlyId);

try {
await this.k8s.core.createNamespacedPod({
Expand Down
6 changes: 0 additions & 6 deletions packages/core/src/v3/isomorphic/friendlyId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,3 @@ export class IdGenerator {
return `${this.prefix}${customAlphabet(this.alphabet, this.length)()}`;
}
}

export const RunnerId = new IdGenerator({
alphabet: "123456789abcdefghijkmnopqrstuvwxyz",
length: 20,
prefix: "runner_",
});