Skip to content

Commit 070d278

Browse files
authored
Merge pull request #874 from useautumn/fix/idle-restart-no-migratios
fix: idle restart no migratios
2 parents 43d03ad + beaa71d commit 070d278

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

server/src/queue/initWorkers.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const isFifoQueue = QUEUE_URL.endsWith(".fifo");
2727
let messagesProcessed = 0;
2828
let totalMessagesProcessed = 0;
2929
let lastStatsTime = Date.now();
30+
let activeMigrationJobs = 0;
3031

3132
// Process recycling — exit after processing this many messages to prevent memory leaks
3233
const MAX_MESSAGES_BEFORE_RECYCLE = 50_000;
@@ -87,7 +88,8 @@ const logStatsAndCheckZeroMessages = () => {
8788

8889
if (
8990
consecutiveZeroMessageIntervals >= IDLE_SELF_KILL_THRESHOLD &&
90-
totalMessagesProcessed > 0
91+
totalMessagesProcessed > 0 &&
92+
activeMigrationJobs === 0
9193
) {
9294
console.log(
9395
`${logPrefix()} Idle self-kill: 0 messages for ${consecutiveZeroMessageIntervals} intervals after processing ${totalMessagesProcessed} total. Exiting for cluster respawn.`,
@@ -272,13 +274,16 @@ const startPollingLoop = async ({ db }: { db: DrizzleCli }) => {
272274
if (!message.Body) continue;
273275
const job: SqsJob = JSON.parse(message.Body);
274276
if (job.name === JobName.Migration) {
275-
handleSingleMessage({ sqs, message, db }).catch((error) => {
276-
console.error(
277-
`${logPrefix()} Migration job failed:`,
278-
error instanceof Error ? error.message : error,
279-
);
280-
Sentry.captureException(error);
281-
});
277+
activeMigrationJobs++;
278+
handleSingleMessage({ sqs, message, db })
279+
.catch((error) => {
280+
console.error(
281+
`${logPrefix()} Migration job failed:`,
282+
error instanceof Error ? error.message : error,
283+
);
284+
Sentry.captureException(error);
285+
})
286+
.finally(() => activeMigrationJobs--);
282287
} else {
283288
regularMessages.push(message);
284289
}

0 commit comments

Comments
 (0)