同步失败回调 开启新事务处理

This commit is contained in:
wkj 2024-09-29 14:41:46 +08:00
parent 1ef5b369ef
commit d0bff1f9b0
2 changed files with 44 additions and 24 deletions

View File

@ -50,17 +50,27 @@ class Synchronizer {
} }
catch (err) { catch (err) {
if (onFailed) { if (onFailed) {
await onFailed({ context.on('rollback', async () => {
remoteEntity: entity, const context2 = this.contextBuilder();
remoteEntityId: entityId, context2.begin();
data: queue.map((ele) => ({ try {
entity: ele.oper.targetEntity, await onFailed({
rowIds: ele.oper.filter.id.$in, remoteEntity: entity,
action: ele.oper.action, remoteEntityId: entityId,
data: ele.oper.data, data: queue.map((ele) => ({
})), entity: ele.oper.targetEntity,
reason: err, rowIds: ele.oper.filter.id.$in,
}, context); action: ele.oper.action,
data: ele.oper.data,
})),
reason: err,
}, context2);
context2.commit();
}
catch (err) {
context2.rollback();
}
});
} }
throw err; throw err;
} }

View File

@ -92,19 +92,29 @@ export default class Synchronizer<ED extends EntityDict & BaseEntityDict, Cxt ex
} }
catch (err: any) { catch (err: any) {
if (onFailed) { if (onFailed) {
await onFailed({ context.on('rollback', async () => {
remoteEntity: entity!, const context2 = this.contextBuilder();
remoteEntityId: entityId!, context2.begin();
data: queue.map( try {
(ele) => ({ await onFailed({
entity: ele.oper.targetEntity!, remoteEntity: entity!,
rowIds: (ele.oper.filter as any).id.$in, // 暂时应该没什么用 remoteEntityId: entityId!,
action: ele.oper.action!, data: queue.map(
data: ele.oper.data!, (ele) => ({
}) entity: ele.oper.targetEntity!,
), rowIds: (ele.oper.filter as any).id.$in, // 暂时应该没什么用
reason: err, action: ele.oper.action!,
}, context); data: ele.oper.data!,
})
),
reason: err,
}, context2);
context2.commit();
}
catch (err) {
context2.rollback();
}
});
} }
throw err; throw err;
} }