@@ -1080,7 +1080,7 @@ class SharedQueueTasks {
1080
1080
1081
1081
const variables = await this . #buildEnvironmentVariables(
1082
1082
attempt . runtimeEnvironment ,
1083
- taskRun ,
1083
+ taskRun . id ,
1084
1084
machinePreset
1085
1085
) ;
1086
1086
@@ -1136,16 +1136,18 @@ class SharedQueueTasks {
1136
1136
return ;
1137
1137
}
1138
1138
1139
- const run = await prisma . taskRun . findUnique ( {
1139
+ const run = await prisma . taskRun . findFirst ( {
1140
1140
where : {
1141
1141
id : runId ,
1142
- runtimeEnvironmentId : environment . id ,
1143
1142
} ,
1144
- include : {
1145
- lockedBy : true ,
1146
- _count : {
1143
+ select : {
1144
+ id : true ,
1145
+ traceContext : true ,
1146
+ friendlyId : true ,
1147
+ isTest : true ,
1148
+ lockedBy : {
1147
1149
select : {
1148
- attempts : true ,
1150
+ machineConfig : true ,
1149
1151
} ,
1150
1152
} ,
1151
1153
} ,
@@ -1156,9 +1158,20 @@ class SharedQueueTasks {
1156
1158
return ;
1157
1159
}
1158
1160
1161
+ const attemptCount = await prisma . taskRunAttempt . count ( {
1162
+ where : {
1163
+ taskRunId : run . id ,
1164
+ } ,
1165
+ } ) ;
1166
+
1167
+ logger . debug ( "Getting lazy attempt payload for run" , {
1168
+ run,
1169
+ attemptCount,
1170
+ } ) ;
1171
+
1159
1172
const machinePreset = machinePresetFromConfig ( run . lockedBy ?. machineConfig ?? { } ) ;
1160
1173
1161
- const variables = await this . #buildEnvironmentVariables( environment , run , machinePreset ) ;
1174
+ const variables = await this . #buildEnvironmentVariables( environment , run . id , machinePreset ) ;
1162
1175
1163
1176
return {
1164
1177
traceContext : run . traceContext as Record < string , unknown > ,
@@ -1169,7 +1182,7 @@ class SharedQueueTasks {
1169
1182
runId : run . friendlyId ,
1170
1183
messageId : run . id ,
1171
1184
isTest : run . isTest ,
1172
- attemptCount : run . _count . attempts ,
1185
+ attemptCount,
1173
1186
} satisfies TaskRunExecutionLazyAttemptPayload ;
1174
1187
}
1175
1188
@@ -1203,21 +1216,21 @@ class SharedQueueTasks {
1203
1216
1204
1217
async #buildEnvironmentVariables(
1205
1218
environment : RuntimeEnvironment ,
1206
- run : TaskRun ,
1219
+ runId : string ,
1207
1220
machinePreset : MachinePreset
1208
1221
) : Promise < Array < EnvironmentVariable > > {
1209
1222
const variables = await resolveVariablesForEnvironment ( environment ) ;
1210
1223
1211
1224
const jwt = await generateJWTTokenForEnvironment ( environment , {
1212
- run_id : run . id ,
1225
+ run_id : runId ,
1213
1226
machine_preset : machinePreset . name ,
1214
1227
} ) ;
1215
1228
1216
1229
return [
1217
1230
...variables ,
1218
1231
...[
1219
1232
{ key : "TRIGGER_JWT" , value : jwt } ,
1220
- { key : "TRIGGER_RUN_ID" , value : run . id } ,
1233
+ { key : "TRIGGER_RUN_ID" , value : runId } ,
1221
1234
{
1222
1235
key : "TRIGGER_MACHINE_PRESET" ,
1223
1236
value : machinePreset . name ,
0 commit comments