mirror of
https://github.com/fosrl/pangolin.git
synced 2026-08-26 14:04:57 +02:00
Move the messaging out of the transaction
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
db,
|
db,
|
||||||
|
primaryDb,
|
||||||
newts,
|
newts,
|
||||||
blueprints,
|
blueprints,
|
||||||
Blueprint,
|
Blueprint,
|
||||||
@@ -80,11 +81,22 @@ export async function applyBlueprint({
|
|||||||
trx,
|
trx,
|
||||||
siteId
|
siteId
|
||||||
);
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Push updates to newts/clients only after the transaction has
|
||||||
|
// committed. Doing this while the transaction is still open can
|
||||||
|
// race with the writes (e.g. newts requesting config before the
|
||||||
|
// new targets/resources are actually visible), leaving them out
|
||||||
|
// of sync until manually toggled.
|
||||||
|
|
||||||
// We need to update the targets on the newts from the successfully updated information
|
// We need to update the targets on the newts from the successfully updated information
|
||||||
for (const result of publicResourcesResults) {
|
for (const result of publicResourcesResults) {
|
||||||
for (const target of result.targetsToUpdate) {
|
for (const target of result.targetsToUpdate) {
|
||||||
const [site] = await trx
|
// read from the primary: this determines whether/how we push
|
||||||
|
// the just-created target to the newt, so a lagging replica
|
||||||
|
// returning stale or missing data here would silently skip
|
||||||
|
// the push
|
||||||
|
const [site] = await primaryDb
|
||||||
.select()
|
.select()
|
||||||
.from(sites)
|
.from(sites)
|
||||||
.innerJoin(newts, eq(sites.siteId, newts.siteId))
|
.innerJoin(newts, eq(sites.siteId, newts.siteId))
|
||||||
@@ -166,7 +178,6 @@ export async function applyBlueprint({
|
|||||||
logger.debug(
|
logger.debug(
|
||||||
`Successfully updated private resources for org ${orgId}: ${JSON.stringify(privateResourcesResults)}`
|
`Successfully updated private resources for org ${orgId}: ${JSON.stringify(privateResourcesResults)}`
|
||||||
);
|
);
|
||||||
});
|
|
||||||
|
|
||||||
blueprintSucceeded = true;
|
blueprintSucceeded = true;
|
||||||
blueprintMessage = "Blueprint applied successfully";
|
blueprintMessage = "Blueprint applied successfully";
|
||||||
|
|||||||
Reference in New Issue
Block a user