Starting to resolve the issue on prediction1

This commit is contained in:
Your Name 2026-10-25 20:56:30 +02:00
parent 633d6683e3
commit 2da5f16d4b
2 changed files with 33 additions and 17 deletions

View File

@ -2118,15 +2118,24 @@ export async function executePlaceBetInternal(
queueUserAdminStatsRefresh(userId);
const mapped = mapBet(bet);
// Redis fan-out must not fail the HTTP bet after ledger/DB commit succeeded.
// A Redis replica READONLY error previously surfaced as a false "DB" failure.
if (config.redis.enabled) {
const betVersion = await bumpUserBetVersionSafe(userId, interval.intervalMinutes);
await publishUserEvent(userId, {
type: 'bet.accepted',
payload: {
bet: mapped as unknown as Record<string, unknown>,
...(betVersion != null ? { versions: { bet: betVersion } } : {}),
},
});
try {
const betVersion = await bumpUserBetVersionSafe(userId, interval.intervalMinutes);
await publishUserEvent(userId, {
type: 'bet.accepted',
payload: {
bet: mapped as unknown as Record<string, unknown>,
...(betVersion != null ? { versions: { bet: betVersion } } : {}),
},
});
} catch (e) {
console.error(
'[candle-predict] post-bet Redis publish failed (bet already committed):',
e instanceof Error ? e.message : e
);
}
}
return mapped;
@ -2217,13 +2226,20 @@ export async function placeBet(
});
if (config.redis.enabled) {
const timingAfter = getActiveRoundTiming(
Date.now(),
interval.intervalMinutes,
interval.predictionWindowSeconds
);
if (timingAfter.phase === 'betting') {
await publishRoundSnapshot(interval.intervalMinutes, timingAfter.openMs);
try {
const timingAfter = getActiveRoundTiming(
Date.now(),
interval.intervalMinutes,
interval.predictionWindowSeconds
);
if (timingAfter.phase === 'betting') {
await publishRoundSnapshot(interval.intervalMinutes, timingAfter.openMs);
}
} catch (e) {
console.error(
'[candle-predict] post-bet round snapshot failed (bet already committed):',
e instanceof Error ? e.message : e
);
}
}

View File

@ -443,8 +443,8 @@ class AppStrings {
String get placeMultiBet => placeMultiPrediction;
String get predictionPlaced => t('Prediction placed', 'Prédiction placée');
String get predictionDbReadonly => t(
'Server database is in read-only mode. Predictions cannot be saved right now — check DATABASE_URL points to the primary database.',
'La base de données du serveur est en lecture seule. Les prédictions ne peuvent pas être enregistrées — vérifiez que DATABASE_URL pointe vers la base principale.',
'Realtime cache (Redis) is read-only. Your prediction may still have been saved — check Recent predictions, then restart Redis as a primary (not a replica).',
'Le cache temps réel (Redis) est en lecture seule. Votre prédiction a peut‑être quand même été enregistrée — vérifiez l’historique, puis redémarrez Redis en mode primaire (pas réplique).',
);
String stakeAmountTitle(String coin) => t('Amount ($coin)', 'Montant ($coin)');
String stakeAmountHint(num min, num max) => t(