Fix rerun
This commit is contained in:
@@ -27,44 +27,45 @@ export class ReRunService {
|
||||
},
|
||||
});
|
||||
|
||||
const eventLog = await this.#prismaClient.eventRecord.create({
|
||||
data: {
|
||||
organization: {
|
||||
connect: {
|
||||
id: existingRun.environment.organizationId,
|
||||
},
|
||||
},
|
||||
project: {
|
||||
connect: {
|
||||
id: existingRun.environment.projectId,
|
||||
},
|
||||
},
|
||||
environment: {
|
||||
connect: {
|
||||
id: existingRun.environment.id,
|
||||
},
|
||||
},
|
||||
externalAccount: existingRun.externalAccount
|
||||
? {
|
||||
connect: {
|
||||
id: existingRun.externalAccount.id,
|
||||
},
|
||||
}
|
||||
: undefined,
|
||||
eventId: `${existingRun.id}-batch:retry:${new Date().getTime()}`,
|
||||
name: existingRun.event.name,
|
||||
timestamp: new Date(),
|
||||
// Get payload directly from Run if batched
|
||||
payload:
|
||||
existingRun.batched && existingRun.payload
|
||||
? (JSON.parse(existingRun.payload) as Prisma.InputJsonValue)
|
||||
: existingRun.event.payload ?? {},
|
||||
context: existingRun.event.context ?? {},
|
||||
source: existingRun.event.source,
|
||||
isTest: existingRun.event.isTest,
|
||||
const eventIds = existingRun.eventIds.length
|
||||
? existingRun.eventIds
|
||||
: [existingRun.event.id];
|
||||
|
||||
const eventRecords = await this.#prismaClient.eventRecord.findMany({
|
||||
where: {
|
||||
id: { in: eventIds },
|
||||
},
|
||||
});
|
||||
|
||||
if (eventIds.length !== eventRecords.length) {
|
||||
throw new Error(
|
||||
`Event records don't match. Found ${eventRecords.length}, expected ${eventIds.length}`
|
||||
);
|
||||
}
|
||||
|
||||
const eventLogs = await Promise.all(
|
||||
eventRecords.map((event) =>
|
||||
this.#prismaClient.eventRecord.create({
|
||||
data: {
|
||||
organizationId: existingRun.environment.organizationId,
|
||||
projectId: existingRun.environment.projectId,
|
||||
environmentId: existingRun.environment.id,
|
||||
externalAccountId: existingRun.externalAccount?.id,
|
||||
eventId: `${event.id}:retry:${new Date().getTime()}`,
|
||||
name: event.name,
|
||||
timestamp: new Date(),
|
||||
payload: event.payload ?? {},
|
||||
context: event.context ?? {},
|
||||
source: event.source,
|
||||
isTest: event.isTest,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
},
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
const createRunService = new CreateRunService(tx);
|
||||
|
||||
return createRunService.call({
|
||||
@@ -73,7 +74,7 @@ export class ReRunService {
|
||||
organization: existingRun.organization,
|
||||
project: existingRun.project,
|
||||
},
|
||||
eventIds: [eventLog.id],
|
||||
eventIds: eventLogs.map((e) => e.id),
|
||||
job: existingRun.job,
|
||||
version: existingRun.version,
|
||||
batched: existingRun.batched,
|
||||
|
||||
Reference in New Issue
Block a user