fix(auction): harden lifecycle and durable bid storage
Serialize lifecycle changes and make cancellation, deadlines, and match side effects recoverable and idempotent. Archive accepted bids durably, quarantine invalid payloads, and preserve compatibility with empty round IDs. Synchronize HTTP polling and socket state with scoped resync events. Add cancellation cleanup index migration and regression coverage. Validated with 744 API tests, 65 Redis integration tests, and 28 Mongo integration tests.
This commit is contained in:
1 parent
f2eec479d9
commit
f649490cd2
55 files changed
+5374
-522
No files matched your search
@@ -12,6 +12,7 @@ import {
|
||||
competitionModelDefinitions,
|
||||
} from '../../competition/competition.schema';
|
||||
import { ModelDefinition } from './types';
|
||||
import { AUCTION_CANCELLATION_CLEANUP_INDEX } from './auction-cancellation-index';
|
||||
|
||||
export type Position = 'TOP' | 'JGL' | 'MID' | 'ADC' | 'SUP';
|
||||
export const POSITIONS: Position[] = ['TOP', 'JGL', 'MID', 'ADC', 'SUP'];
|
||||
@@ -700,6 +701,12 @@ export interface Match extends MongooseTimestamps {
|
||||
teams: MatchTeam[];
|
||||
result?: MatchResult;
|
||||
resultPollState?: MatchResultPollState;
|
||||
/** 마지막으로 취소된 Redis 경매 lifecycle. 취소 재전송을 멱등 처리한다. */
|
||||
lastCancelledAuctionLifecycleId?: string;
|
||||
auctionCancellationCleanupPending?: boolean;
|
||||
auctionCancellationCleanupRetryAt?: Date;
|
||||
auctionCancellationCleanupAttempts?: number;
|
||||
auctionCancellationCleanupError?: string;
|
||||
doubleElimination?: DoubleEliminationBracket;
|
||||
legacyImported?: boolean;
|
||||
legacyImportSource?: {
|
||||
@@ -804,12 +811,41 @@ export interface AuctionBid {
|
||||
}
|
||||
|
||||
export interface AuctionBidHistoryEntry {
|
||||
bidRequestId?: string;
|
||||
revision?: number;
|
||||
bidRoundId?: string;
|
||||
playerUserId?: mongoose.Types.ObjectId;
|
||||
bidderTeamIndex: number;
|
||||
bidPointAmount: number;
|
||||
bidderUserId: mongoose.Types.ObjectId;
|
||||
bidPlacedAtTimestampMS: number;
|
||||
}
|
||||
|
||||
export interface AuctionBidRecord extends AuctionBidHistoryEntry {
|
||||
_id: string;
|
||||
matchId: mongoose.Types.ObjectId;
|
||||
auctionLifecycleId: string;
|
||||
revision: number;
|
||||
bidRequestId: string;
|
||||
}
|
||||
|
||||
export const AuctionBidRecordSchema = new Schema<AuctionBidRecord>(
|
||||
{
|
||||
_id: { type: String, required: true },
|
||||
matchId: { type: Schema.Types.ObjectId, required: true },
|
||||
auctionLifecycleId: { type: String, required: true },
|
||||
revision: { type: Number, required: true },
|
||||
bidRequestId: { type: String, required: true },
|
||||
bidRoundId: { type: String },
|
||||
playerUserId: { type: Schema.Types.ObjectId },
|
||||
bidderUserId: { type: Schema.Types.ObjectId, required: true },
|
||||
bidderTeamIndex: { type: Number, required: true },
|
||||
bidPointAmount: { type: Number, required: true },
|
||||
bidPlacedAtTimestampMS: { type: Number, required: true },
|
||||
},
|
||||
{ collection: 'auctionBidRecords', versionKey: false },
|
||||
);
|
||||
|
||||
export interface AuctionChatMessage {
|
||||
id: string;
|
||||
userId?: mongoose.Types.ObjectId;
|
||||
@@ -832,6 +868,8 @@ export interface Auction extends MongooseTimestamps {
|
||||
matchSideEffectStatus: AuctionMatchSideEffectStatus;
|
||||
matchSideEffectRevision: number;
|
||||
matchSideEffectError?: string;
|
||||
matchSideEffectTransitionId?: string;
|
||||
startupCompleted?: boolean;
|
||||
teams: AuctionTeam[];
|
||||
order: AuctionPlayerSnapshot[];
|
||||
passedQueue: AuctionPlayerSnapshot[];
|
||||
@@ -858,6 +896,7 @@ export interface Auction extends MongooseTimestamps {
|
||||
currentHighestBidPointAmount?: number;
|
||||
currentHighestBidderTeamIndex?: number;
|
||||
currentBidRoundDeadlineTimestampMS?: number;
|
||||
currentBidRoundId?: string;
|
||||
maximumBidRoundDurationSeconds?: number;
|
||||
bidRoundExtensionSeconds?: number;
|
||||
initialTeamBidPointAmount?: number;
|
||||
@@ -1971,6 +2010,11 @@ export const MatchSchema = new Schema<Match>(
|
||||
type: MatchResultPollStateSubSchema,
|
||||
required: false,
|
||||
},
|
||||
lastCancelledAuctionLifecycleId: { type: String, required: false },
|
||||
auctionCancellationCleanupPending: { type: Boolean },
|
||||
auctionCancellationCleanupRetryAt: { type: Date },
|
||||
auctionCancellationCleanupAttempts: { type: Number },
|
||||
auctionCancellationCleanupError: { type: String },
|
||||
doubleElimination: {
|
||||
type: DoubleEliminationBracketSubSchema,
|
||||
required: false,
|
||||
@@ -1995,6 +2039,10 @@ export const MatchSchema = new Schema<Match>(
|
||||
);
|
||||
|
||||
MatchSchema.index({ communityId: 1, scheduledAt: -1 });
|
||||
MatchSchema.index(
|
||||
AUCTION_CANCELLATION_CLEANUP_INDEX.key,
|
||||
AUCTION_CANCELLATION_CLEANUP_INDEX.options,
|
||||
);
|
||||
applyCompetitionDomainInvariantIndexes(MatchSchema, 'match');
|
||||
MatchSchema.index({ communityId: 1, status: 1, scheduledAt: -1 });
|
||||
MatchSchema.index(
|
||||
@@ -2174,6 +2222,8 @@ const AuctionBidSubSchema = new Schema<AuctionBid>(
|
||||
|
||||
const AuctionBidHistoryEntrySubSchema = new Schema<AuctionBidHistoryEntry>(
|
||||
{
|
||||
bidRoundId: { type: String },
|
||||
playerUserId: { type: Schema.Types.ObjectId, ref: 'user' },
|
||||
bidderTeamIndex: { type: Number, required: true, min: 1 },
|
||||
bidPointAmount: { type: Number, required: true },
|
||||
bidderUserId: { type: Schema.Types.ObjectId, ref: 'user', required: true },
|
||||
@@ -2195,6 +2245,9 @@ const AuctionChatMessageSubSchema = new Schema<AuctionChatMessage>(
|
||||
|
||||
export const AuctionSchema = new Schema<Auction>(
|
||||
{
|
||||
startupCompleted: { type: Boolean },
|
||||
matchSideEffectTransitionId: { type: String },
|
||||
currentBidRoundId: { type: String },
|
||||
matchId: {
|
||||
type: Schema.Types.ObjectId,
|
||||
ref: 'match',
|
||||
@@ -2520,6 +2573,11 @@ export const tournamentModelDefinitions: Array<
|
||||
},
|
||||
{ name: 'match', schema: MatchSchema, schemaName: 'match' },
|
||||
{ name: 'auction', schema: AuctionSchema, schemaName: 'auction' },
|
||||
{
|
||||
name: 'auctionBidRecord',
|
||||
schema: AuctionBidRecordSchema,
|
||||
schemaName: 'auctionBidRecords',
|
||||
},
|
||||
{
|
||||
name: 'auctionHistory',
|
||||
schema: AuctionHistoryEntrySchema,
|
||||
@@ -2553,6 +2611,7 @@ export interface TournamentModelTypes {
|
||||
legacyImportJob: LegacyImportJob;
|
||||
match: Match;
|
||||
auction: Auction;
|
||||
auctionBidRecord: AuctionBidRecord;
|
||||
auctionHistory: AuctionHistoryEntry;
|
||||
auctionSideEffectApplication: AuctionSideEffectApplication;
|
||||
matchStats: MatchStats;
|
||||
|
||||
Reference in new issue
Block a user