@@ -20,13 +20,13 @@ type WorkloadHttpClientOptions = WorkloadClientCommonOptions;
20
20
21
21
export class WorkloadHttpClient {
22
22
private apiUrl : string ;
23
+ private runnerId : string ;
23
24
private readonly deploymentId : string ;
24
- private readonly defaultHeaders : Record < string , string > ;
25
25
26
- constructor ( opts : WorkloadHttpClientOptions ) {
26
+ constructor ( private opts : WorkloadHttpClientOptions ) {
27
27
this . apiUrl = opts . workerApiUrl . replace ( / \/ $ / , "" ) ;
28
- this . defaultHeaders = getDefaultWorkloadHeaders ( opts ) ;
29
28
this . deploymentId = opts . deploymentId ;
29
+ this . runnerId = opts . runnerId ;
30
30
31
31
if ( ! this . apiUrl ) {
32
32
throw new Error ( "apiURL is required and needs to be a non-empty string" ) ;
@@ -41,14 +41,25 @@ export class WorkloadHttpClient {
41
41
this . apiUrl = apiUrl . replace ( / \/ $ / , "" ) ;
42
42
}
43
43
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
+
44
55
async heartbeatRun ( runId : string , snapshotId : string , body ?: WorkloadHeartbeatRequestBody ) {
45
56
return wrapZodFetch (
46
57
WorkloadHeartbeatResponseBody ,
47
58
`${ this . apiUrl } /api/v1/workload-actions/runs/${ runId } /snapshots/${ snapshotId } /heartbeat` ,
48
59
{
49
60
method : "POST" ,
50
61
headers : {
51
- ...this . defaultHeaders ,
62
+ ...this . defaultHeaders ( ) ,
52
63
"Content-Type" : "application/json" ,
53
64
} ,
54
65
body : JSON . stringify ( body ?? { } ) ,
@@ -63,7 +74,7 @@ export class WorkloadHttpClient {
63
74
{
64
75
method : "GET" ,
65
76
headers : {
66
- ...this . defaultHeaders ,
77
+ ...this . defaultHeaders ( ) ,
67
78
} ,
68
79
}
69
80
) ;
@@ -76,7 +87,7 @@ export class WorkloadHttpClient {
76
87
{
77
88
method : "GET" ,
78
89
headers : {
79
- ...this . defaultHeaders ,
90
+ ...this . defaultHeaders ( ) ,
80
91
} ,
81
92
}
82
93
) ;
@@ -93,7 +104,7 @@ export class WorkloadHttpClient {
93
104
{
94
105
method : "POST" ,
95
106
headers : {
96
- ...this . defaultHeaders ,
107
+ ...this . defaultHeaders ( ) ,
97
108
} ,
98
109
body : JSON . stringify ( body ) ,
99
110
}
@@ -111,7 +122,7 @@ export class WorkloadHttpClient {
111
122
{
112
123
method : "POST" ,
113
124
headers : {
114
- ...this . defaultHeaders ,
125
+ ...this . defaultHeaders ( ) ,
115
126
} ,
116
127
body : JSON . stringify ( body ) ,
117
128
}
@@ -125,7 +136,7 @@ export class WorkloadHttpClient {
125
136
{
126
137
method : "GET" ,
127
138
headers : {
128
- ...this . defaultHeaders ,
139
+ ...this . defaultHeaders ( ) ,
129
140
} ,
130
141
}
131
142
) ;
@@ -139,7 +150,7 @@ export class WorkloadHttpClient {
139
150
{
140
151
method : "POST" ,
141
152
headers : {
142
- ...this . defaultHeaders ,
153
+ ...this . defaultHeaders ( ) ,
143
154
"Content-Type" : "application/json" ,
144
155
} ,
145
156
body : JSON . stringify ( body ) ,
@@ -161,7 +172,7 @@ export class WorkloadHttpClient {
161
172
{
162
173
method : "GET" ,
163
174
headers : {
164
- ...this . defaultHeaders ,
175
+ ...this . defaultHeaders ( ) ,
165
176
} ,
166
177
}
167
178
) ;
0 commit comments