Keep account fallback healthy across concurrent upload failures
CI / verify (push) Canceled after 0s
CI / verify (push) Canceled after 0s
This commit is contained in:
1 parent
e9287545ee
commit
2ba21993c8
3 files changed
+50
-17
No files matched your search
+20
-4
@@ -12,7 +12,7 @@ const Semaphore = require('./semaphore');
|
||||
const Throttle = require('./throttle');
|
||||
const { probeFileHead } = require('./file-probe');
|
||||
const { normalizeFailureDetails } = require('./upload-diagnostics');
|
||||
const { classifyAccountFailure } = require('./account-rotation');
|
||||
const { classifyAccountFailure, selectFallbackAccount } = require('./account-rotation');
|
||||
|
||||
const DEFAULT_SETTINGS = {
|
||||
retries: 3,
|
||||
@@ -97,6 +97,18 @@ class UploadManager extends EventEmitter {
|
||||
return this._accountOverrides.get(hoster) || null;
|
||||
}
|
||||
|
||||
_getFallbackAccount(hoster, currentAccountId, excludedIds) {
|
||||
const override = this.getOverride(hoster);
|
||||
return selectFallbackAccount({
|
||||
accounts: this.accountPools[hoster] || (override ? [override] : []),
|
||||
hoster,
|
||||
currentAccountId,
|
||||
failedKeys: this._failedAccounts,
|
||||
preferredAccountId: override?.id,
|
||||
excludedIds
|
||||
});
|
||||
}
|
||||
|
||||
getActiveJobCount() {
|
||||
return this.activeJobs.size;
|
||||
}
|
||||
@@ -123,7 +135,9 @@ class UploadManager extends EventEmitter {
|
||||
}
|
||||
|
||||
_emitAccountSucceeded(task) {
|
||||
if (task?.hoster && task?.accountId) this.emit('account-succeeded', { hoster: task.hoster, accountId: task.accountId });
|
||||
if (task?.hoster && task?.accountId && !this._failedAccounts.has(`${task.hoster}:${task.accountId}`)) {
|
||||
this.emit('account-succeeded', { hoster: task.hoster, accountId: task.accountId });
|
||||
}
|
||||
}
|
||||
|
||||
// True if the hoster has a usable override stored that differs from the
|
||||
@@ -604,7 +618,7 @@ class UploadManager extends EventEmitter {
|
||||
// with 500 queued jobs and 1 parallel slot, without this check every
|
||||
// job still hits the original dead account first.
|
||||
if (task.accountId && this._failedAccounts.has(task.hoster + ':' + task.accountId)) {
|
||||
const override = this._accountOverrides.get(task.hoster);
|
||||
const override = this._getFallbackAccount(task.hoster, task.accountId);
|
||||
if (override && !this._failedAccounts.has(task.hoster + ':' + override.id)) {
|
||||
this._rotLog('pre-job-swap', {
|
||||
jobId, hoster: task.hoster, fileName, fromAccountId: task.accountId, toAccountId: override.id
|
||||
@@ -952,6 +966,7 @@ class UploadManager extends EventEmitter {
|
||||
recordFinalResult('error', { error });
|
||||
return;
|
||||
}
|
||||
const attemptedAccounts = new Set([task.accountId]);
|
||||
while (task.accountId) {
|
||||
if (signal.aborted || this.stopAfterActive) break;
|
||||
// The rotated-to account failed with a file-class error (file
|
||||
@@ -995,7 +1010,7 @@ class UploadManager extends EventEmitter {
|
||||
lastError: lastError ? lastError.message : null
|
||||
});
|
||||
}
|
||||
const override = this._accountOverrides.get(task.hoster);
|
||||
const override = this._getFallbackAccount(task.hoster, task.accountId, attemptedAccounts);
|
||||
if (!override) {
|
||||
this._rotLog('rotation-end', {
|
||||
jobId, hoster: task.hoster, fileName, reason: 'no-override-set',
|
||||
@@ -1023,6 +1038,7 @@ class UploadManager extends EventEmitter {
|
||||
fromAccountId: task.accountId, toAccountId: override.id
|
||||
});
|
||||
task.accountId = override.id;
|
||||
attemptedAccounts.add(override.id);
|
||||
task.username = override.username;
|
||||
task.password = override.password;
|
||||
task.apiKey = override.apiKey;
|
||||
|
||||
Reference in new issue
Block a user