Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 32 additions & 21 deletions powerdeletesuite.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ var pd = {
});
},
createProcessStream: function () {
pd.backoff.reset();
window.pd_processing = true;
pd.exportItems = [];
pd.exportIds = [];
Expand Down Expand Up @@ -548,6 +549,22 @@ var pd = {
});
},
},
backoff: {
delay: 1000,
maxDelay: 1024000,
schedule: function (fn) {
console.log(
"[PowerDeleteSuite] Rate limited (429). Backing off for " +
pd.backoff.delay / 1000 +
"s before retrying..."
);
setTimeout(fn, pd.backoff.delay);
pd.backoff.delay = Math.min(pd.backoff.delay * 2, pd.backoff.maxDelay);
},
reset: function () {
pd.backoff.delay = 1000;
},
},
helpers: {
validate: function () {
if (pd.task.config.isEditing && pd.task.config.editText === "") {
Expand Down Expand Up @@ -885,22 +902,18 @@ var pd = {
},
}).then(
function () {
pd.backoff.reset();
pd.task.items[0].pdDeleted = true;
pd.actions.children.handleSingle();
},
function () {
function (jqXHR) {
pd.task.info.errors++;
if (
confirm(
"Error deleting " +
(item.kind == "t3" ? "post" : "comment") +
", would you like to retry?"
)
) {
pd.actions.children.handleSingle();
if (jqXHR.status === 429) {
pd.backoff.schedule(function () {
pd.actions.children.handleSingle();
});
} else {
pd.actions.children.finishItem();
pd.actions.children.handleGroup();
pd.actions.children.handleSingle();
}
}
);
Expand Down Expand Up @@ -929,21 +942,19 @@ var pd = {
},
}).then(
function () {
pd.backoff.reset();
pd.task.items[0].pdEdited = true;
pd.actions.children.handleSingle();
},
function () {
function (jqXHR) {
pd.task.info.errors++;
if (
!confirm(
"Error editing " +
(item.kind == "t3" ? "post" : "comment") +
", would you like to retry?"
)
) {
item.pdEdited = true;
if (jqXHR.status === 429) {
pd.backoff.schedule(function () {
pd.actions.children.handleSingle();
});
} else {
pd.actions.children.handleSingle();
}
pd.actions.children.handleSingle();
}
);
} else {
Expand Down