Skip to content

Commit 5f45507

Browse files
committed
update runner id on restore
1 parent c260a5c commit 5f45507

File tree

2 files changed

+33
-12
lines changed

2 files changed

+33
-12
lines changed

packages/cli-v3/src/entryPoints/managed-run-controller.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ type Metadata = {
8686
TRIGGER_SNAPSHOT_POLL_INTERVAL_SECONDS: number | undefined;
8787
TRIGGER_SUCCESS_EXIT_CODE: number | undefined;
8888
TRIGGER_FAILURE_EXIT_CODE: number | undefined;
89+
TRIGGER_RUNNER_ID: string | undefined;
8990
};
9091

9192
class MetadataClient {
@@ -126,6 +127,8 @@ class ManagedRunController {
126127
private workerApiUrl: string;
127128
private workerInstanceName: string;
128129

130+
private runnerId: string;
131+
129132
private successExitCode = env.TRIGGER_SUCCESS_EXIT_CODE;
130133
private failureExitCode = env.TRIGGER_FAILURE_EXIT_CODE;
131134

@@ -144,6 +147,8 @@ class ManagedRunController {
144147

145148
this.workerManifest = opts.workerManifest;
146149

150+
this.runnerId = env.TRIGGER_RUNNER_ID;
151+
147152
this.heartbeatIntervalSeconds = env.TRIGGER_HEARTBEAT_INTERVAL_SECONDS;
148153
this.snapshotPollIntervalSeconds = env.TRIGGER_SNAPSHOT_POLL_INTERVAL_SECONDS;
149154

@@ -156,7 +161,7 @@ class ManagedRunController {
156161

157162
this.httpClient = new WorkloadHttpClient({
158163
workerApiUrl: this.workerApiUrl,
159-
runnerId: env.TRIGGER_RUNNER_ID,
164+
runnerId: this.runnerId,
160165
deploymentId: env.TRIGGER_DEPLOYMENT_ID,
161166
deploymentVersion: env.TRIGGER_DEPLOYMENT_VERSION,
162167
projectRef: env.TRIGGER_PROJECT_REF,
@@ -709,6 +714,11 @@ class ManagedRunController {
709714

710715
this.httpClient.updateApiUrl(this.workerApiUrl);
711716
}
717+
718+
if (overrides.TRIGGER_RUNNER_ID) {
719+
this.runnerId = overrides.TRIGGER_RUNNER_ID;
720+
this.httpClient.updateRunnerId(this.runnerId);
721+
}
712722
}
713723

714724
private async startAndExecuteRunAttempt({

packages/core/src/v3/runEngineWorker/workload/http.ts

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ type WorkloadHttpClientOptions = WorkloadClientCommonOptions;
2020

2121
export class WorkloadHttpClient {
2222
private apiUrl: string;
23+
private runnerId: string;
2324
private readonly deploymentId: string;
24-
private readonly defaultHeaders: Record<string, string>;
2525

26-
constructor(opts: WorkloadHttpClientOptions) {
26+
constructor(private opts: WorkloadHttpClientOptions) {
2727
this.apiUrl = opts.workerApiUrl.replace(/\/$/, "");
28-
this.defaultHeaders = getDefaultWorkloadHeaders(opts);
2928
this.deploymentId = opts.deploymentId;
29+
this.runnerId = opts.runnerId;
3030

3131
if (!this.apiUrl) {
3232
throw new Error("apiURL is required and needs to be a non-empty string");
@@ -41,14 +41,25 @@ export class WorkloadHttpClient {
4141
this.apiUrl = apiUrl.replace(/\/$/, "");
4242
}
4343

44+
updateRunnerId(runnerId: string) {
45+
this.runnerId = runnerId;
46+
}
47+
48+
defaultHeaders(): Record<string, string> {
49+
return getDefaultWorkloadHeaders({
50+
...this.opts,
51+
runnerId: this.runnerId,
52+
});
53+
}
54+
4455
async heartbeatRun(runId: string, snapshotId: string, body?: WorkloadHeartbeatRequestBody) {
4556
return wrapZodFetch(
4657
WorkloadHeartbeatResponseBody,
4758
`${this.apiUrl}/api/v1/workload-actions/runs/${runId}/snapshots/${snapshotId}/heartbeat`,
4859
{
4960
method: "POST",
5061
headers: {
51-
...this.defaultHeaders,
62+
...this.defaultHeaders(),
5263
"Content-Type": "application/json",
5364
},
5465
body: JSON.stringify(body ?? {}),
@@ -63,7 +74,7 @@ export class WorkloadHttpClient {
6374
{
6475
method: "GET",
6576
headers: {
66-
...this.defaultHeaders,
77+
...this.defaultHeaders(),
6778
},
6879
}
6980
);
@@ -76,7 +87,7 @@ export class WorkloadHttpClient {
7687
{
7788
method: "GET",
7889
headers: {
79-
...this.defaultHeaders,
90+
...this.defaultHeaders(),
8091
},
8192
}
8293
);
@@ -93,7 +104,7 @@ export class WorkloadHttpClient {
93104
{
94105
method: "POST",
95106
headers: {
96-
...this.defaultHeaders,
107+
...this.defaultHeaders(),
97108
},
98109
body: JSON.stringify(body),
99110
}
@@ -111,7 +122,7 @@ export class WorkloadHttpClient {
111122
{
112123
method: "POST",
113124
headers: {
114-
...this.defaultHeaders,
125+
...this.defaultHeaders(),
115126
},
116127
body: JSON.stringify(body),
117128
}
@@ -125,7 +136,7 @@ export class WorkloadHttpClient {
125136
{
126137
method: "GET",
127138
headers: {
128-
...this.defaultHeaders,
139+
...this.defaultHeaders(),
129140
},
130141
}
131142
);
@@ -139,7 +150,7 @@ export class WorkloadHttpClient {
139150
{
140151
method: "POST",
141152
headers: {
142-
...this.defaultHeaders,
153+
...this.defaultHeaders(),
143154
"Content-Type": "application/json",
144155
},
145156
body: JSON.stringify(body),
@@ -161,7 +172,7 @@ export class WorkloadHttpClient {
161172
{
162173
method: "GET",
163174
headers: {
164-
...this.defaultHeaders,
175+
...this.defaultHeaders(),
165176
},
166177
}
167178
);

0 commit comments

Comments
 (0)