fix: harden multi-instance scheduler and worker execution

This commit is contained in:
dahyeon committed 2026-06-27 13:19:43 -07:00
1 parent df7dcd3a9c
commit 60a006008a
23 files changed
+1442 -299

No files matched your search

@@ -42,4 +42,21 @@ describe('resolveMongoConnectionOptions', () => {
autoCreate: false,
});
});
it('enables automatic index creation when explicitly requested', () => {
expect(
resolveMongoConnectionOptions(
'lolympus-staging',
'lolympus-api:staging:1',
'true',
),
).toEqual({
dbName: 'lolympus-staging',
appName: 'lolympus-api:staging:1',
minPoolSize: 10,
maxPoolSize: 20,
autoIndex: true,
autoCreate: false,
});
});
});
@@ -19,13 +19,17 @@ export function resolveMongoAppName(
export function resolveMongoConnectionOptions(
dbName: string,
appName: string,
mongoAutoIndex = process.env.MONGODB_AUTO_INDEX,
): mongoose.ConnectOptions {
const shouldEnableMongoAutoIndex =
mongoAutoIndex?.trim().toLowerCase() === 'true';
return {
dbName,
appName,
minPoolSize: 10,
maxPoolSize: 20,
autoIndex: false,
autoIndex: shouldEnableMongoAutoIndex,
autoCreate: false,
};
}
@@ -392,6 +392,8 @@ export interface DakaoOutboxMessage extends MongooseTimestamps {
payload: Record<string, unknown>;
state: DakaoOutboxMessageState;
publishAttempts: number;
publishLeaseOwnerIdentifier?: string;
publishLeaseExpiresAt?: Date;
publishedAt?: Date;
terminalAt?: Date;
resultEventId?: string;
@@ -733,6 +735,7 @@ export interface LegacyImportJob extends MongooseTimestamps {
totalSkippedDuplicate: number;
totalErrors: number;
averageMemberSeconds?: number;
completedMemberJobIds: string[];
errors?: LegacyImportJobError[];
}
@@ -1282,6 +1285,8 @@ export const DakaoOutboxMessageSchema = new Schema<DakaoOutboxMessage>(
default: 'pending',
},
publishAttempts: { type: Number, required: true, default: 0 },
publishLeaseOwnerIdentifier: { type: String },
publishLeaseExpiresAt: { type: Date },
publishedAt: { type: Date },
terminalAt: { type: Date },
resultEventId: { type: String },
@@ -1302,6 +1307,11 @@ export const DakaoOutboxMessageSchema = new Schema<DakaoOutboxMessage>(
);
DakaoOutboxMessageSchema.index({ state: 1, updatedAt: 1 });
DakaoOutboxMessageSchema.index({
state: 1,
publishLeaseExpiresAt: 1,
updatedAt: 1,
});
DakaoOutboxMessageSchema.index({ correlationId: 1 }, { sparse: true });
export const DakaoSendResultEventSchema = new Schema<DakaoSendResultEvent>(
@@ -1988,6 +1998,11 @@ export const LegacyImportJobSchema = new Schema<LegacyImportJob>(
totalSkippedDuplicate: { type: Number, required: true, default: 0 },
totalErrors: { type: Number, required: true, default: 0 },
averageMemberSeconds: { type: Number },
completedMemberJobIds: {
type: [String],
required: true,
default: [],
},
errors: {
type: [LegacyImportJobErrorSubSchema],
required: true,
@@ -2003,6 +2018,7 @@ export const LegacyImportJobSchema = new Schema<LegacyImportJob>(
LegacyImportJobSchema.index({ communityId: 1, startedAt: -1 });
LegacyImportJobSchema.index({ communityId: 1, state: 1 });
LegacyImportJobSchema.index({ jobId: 1, completedMemberJobIds: 1 });
const AuctionPlayerSnapshotSubSchema = new Schema<AuctionPlayerSnapshot>(
{