fix: 修复小程序构建进度死锁
This commit is contained in:
1 parent
f7be18a35e
commit
a933e1feb6
2 files changed
+30
-29
No files matched your search
@@ -151,36 +151,33 @@ export class AdminMiniAppReleaseService {
|
||||
buildLogs?: unknown;
|
||||
},
|
||||
): Promise<unknown> {
|
||||
return this.prisma.$transaction(
|
||||
async (tx) => {
|
||||
const task = await tx.miniAppReleaseTask.findFirst({ where: { id: taskId, brandId } });
|
||||
if (!task) throw new NotFoundException("小程序发布任务不存在");
|
||||
const buildStatusChanged =
|
||||
input.buildStatus !== undefined && input.buildStatus !== task.buildStatus;
|
||||
return tx.miniAppReleaseTask.update({
|
||||
where: { id: task.id },
|
||||
data: {
|
||||
...(input.error !== undefined ? { error: input.error } : {}),
|
||||
...(input.buildLogs !== undefined
|
||||
? { buildLogs: input.buildLogs as Prisma.InputJsonValue }
|
||||
: {}),
|
||||
...(input.buildStatus ? { buildStatus: input.buildStatus } : {}),
|
||||
...(buildStatusChanged
|
||||
? {
|
||||
audit: this.audit(task.audit, {
|
||||
action: "build-updated",
|
||||
actorId,
|
||||
from: task.buildStatus,
|
||||
to: input.buildStatus,
|
||||
at: new Date().toISOString(),
|
||||
}),
|
||||
}
|
||||
: {}),
|
||||
},
|
||||
});
|
||||
const task = await this.prisma.miniAppReleaseTask.findFirst({
|
||||
where: { id: taskId, brandId },
|
||||
});
|
||||
if (!task) throw new NotFoundException("小程序发布任务不存在");
|
||||
const buildStatusChanged =
|
||||
input.buildStatus !== undefined && input.buildStatus !== task.buildStatus;
|
||||
return this.prisma.miniAppReleaseTask.update({
|
||||
where: { id: task.id },
|
||||
data: {
|
||||
...(input.error !== undefined ? { error: input.error } : {}),
|
||||
...(input.buildLogs !== undefined
|
||||
? { buildLogs: input.buildLogs as Prisma.InputJsonValue }
|
||||
: {}),
|
||||
...(input.buildStatus ? { buildStatus: input.buildStatus } : {}),
|
||||
...(buildStatusChanged
|
||||
? {
|
||||
audit: this.audit(task.audit, {
|
||||
action: "build-updated",
|
||||
actorId,
|
||||
from: task.buildStatus,
|
||||
to: input.buildStatus,
|
||||
at: new Date().toISOString(),
|
||||
}),
|
||||
}
|
||||
: {}),
|
||||
},
|
||||
{ isolationLevel: Prisma.TransactionIsolationLevel.Serializable },
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
private audit(value: Prisma.JsonValue | null, entry: Record<string, unknown>) {
|
||||
|
||||
@@ -9,6 +9,10 @@ const actorId = "admin-1";
|
||||
|
||||
function createService(task: Record<string, unknown> | null): AdminMiniAppReleaseService {
|
||||
const prisma = {
|
||||
miniAppReleaseTask: {
|
||||
findFirst: async () => task,
|
||||
update: async ({ data }: { data: Record<string, unknown> }) => ({ ...task, ...data }),
|
||||
},
|
||||
$transaction: async (callback: (tx: unknown) => unknown) =>
|
||||
callback({
|
||||
miniAppReleaseTask: {
|
||||
|
||||
Reference in new issue
Block a user