Skip to content

Commit c2c316e

Browse files
committed
Build fixes and tweak for sending bus messages before transaction is done.
1 parent 6dda3ad commit c2c316e

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

docker/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ COPY . /challenge-api
77
WORKDIR /challenge-api
88

99
# Install the dependencies from package.json
10+
RUN git --version
1011
RUN npm i -g pnpm
11-
RUN --mount=type=ssh pnpm install
12+
RUN pnpm install
1213

1314
CMD node /challenge-api/app.js

src/services/ChallengeService.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1859,7 +1859,16 @@ function validateTask(currentUser, challenge, data, challengeResources) {
18591859
* @param {Object} data the challenge data to be updated
18601860
* @returns {Object} the updated challenge
18611861
*/
1862-
async function updateChallenge(currentUser, challengeId, data) {
1862+
// Note: `options` may be a boolean for backward compatibility (emitEvent flag),
1863+
// or an object { emitEvent?: boolean }.
1864+
async function updateChallenge(currentUser, challengeId, data, options = {}) {
1865+
// Backward compatibility for callers passing a boolean as the 4th arg
1866+
let emitEvent = true;
1867+
if (typeof options === "boolean") {
1868+
emitEvent = options;
1869+
} else if (options && Object.prototype.hasOwnProperty.call(options, "emitEvent")) {
1870+
emitEvent = options.emitEvent !== false;
1871+
}
18631872
const challenge = await prisma.challenge.findUnique({
18641873
where: { id: challengeId },
18651874
include: includeReturnFields,
@@ -2437,7 +2446,15 @@ async function updateChallenge(currentUser, challengeId, data) {
24372446
include: includeReturnFields,
24382447
});
24392448
});
2440-
await indexChallengeAndPostToKafka(updatedChallenge, track, type);
2449+
// Re-fetch the challenge outside the transaction to ensure we publish
2450+
// only after the commit succeeds and using the committed snapshot.
2451+
if (emitEvent) {
2452+
const committed = await prisma.challenge.findUnique({
2453+
where: { id: challengeId },
2454+
include: includeReturnFields,
2455+
});
2456+
await indexChallengeAndPostToKafka(committed, track, type);
2457+
}
24412458

24422459
if (updatedChallenge.legacy.selfService) {
24432460
const creator = await helper.getMemberByHandle(updatedChallenge.createdBy);

0 commit comments

Comments
 (0)