queue
This commit is contained in:
@@ -35,9 +35,6 @@ function processQueue(channel, state) {
|
||||
setTimeout(async () => {
|
||||
state.processing = false;
|
||||
// New window
|
||||
if (state.queue.length > 3) {
|
||||
logWarn('renameQueue', `Channel ${channel.name} has ${state.queue.length} renames queued`).catch(() => {});
|
||||
}
|
||||
const item = state.queue.shift();
|
||||
if (!item) return;
|
||||
item.started = true;
|
||||
@@ -77,19 +74,20 @@ function enqueueRename(channel, newName) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
// At limit — queue it
|
||||
const queueSize = state.queue.length + 1;
|
||||
const queuedItem = { newName, started: false };
|
||||
state.queue.push(queuedItem);
|
||||
// At limit — replace pending rename with latest
|
||||
const isNew = state.queue.length === 0;
|
||||
state.queue[0] = { newName, started: false };
|
||||
const queuedItem = state.queue[0];
|
||||
|
||||
// Only notify if this rename is still waiting after ~2s.
|
||||
setTimeout(() => {
|
||||
if (queuedItem.started) return;
|
||||
const estMinutes = Math.max(1, Math.ceil((queueSize * RENAME_WINDOW_MS) / 60000));
|
||||
channel.send(`⏳ Channel will be renamed in ~${estMinutes} minute${estMinutes === 1 ? '' : 's'}.`).catch(() => {});
|
||||
}, 2000);
|
||||
if (isNew) {
|
||||
setTimeout(() => {
|
||||
if (queuedItem.started) return;
|
||||
const estMinutes = Math.ceil(RENAME_WINDOW_MS / 60000);
|
||||
channel.send(`⏳ Channel will be renamed in ~${estMinutes} minute${estMinutes === 1 ? '' : 's'}.`).catch(() => {});
|
||||
}, 2000);
|
||||
|
||||
processQueue(channel, state);
|
||||
processQueue(channel, state);
|
||||
}
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user