retry filesearch when rate-limited

This commit is contained in:
ed 2021-06-23 22:01:06 +02:00
parent 9722441aad
commit f1870daf0d
2 changed files with 20 additions and 3 deletions

View File

@ -638,7 +638,7 @@ class HttpCli(object):
penalty = 0.7
t_idle = t0 - idx.p_end
if idx.p_dur > 0.7 and t_idle < penalty:
m = "rate-limit ({:.1f} sec), cost {:.2f}, idle {:.2f}"
m = "rate-limit {:.1f} sec, cost {:.2f}, idle {:.2f}"
raise Pebkac(429, m.format(penalty, idx.p_dur, t_idle))
if "srch" in body:

View File

@ -740,9 +740,17 @@ function up2k_init(subtle) {
function handshakes_permitted() {
var lim = multitask ? 1 : 0;
return lim >=
if (lim <
st.todo.upload.length +
st.busy.upload.length;
st.busy.upload.length)
return false;
var cd = st.todo.handshake.length ? st.todo.handshake[0].cooldown : 0;
if (cd && cd - Date.now() > 0)
return false;
return true;
}
function hashing_permitted() {
@ -1155,6 +1163,15 @@ function up2k_init(subtle) {
if (rsp.indexOf('<pre>') === 0)
rsp = rsp.slice(5);
if (rsp.indexOf('rate-limit ') !== -1) {
var penalty = rsp.replace(/.*rate-limit /, "").split(' ')[0];
console.log("rate-limit: " + penalty);
t.cooldown = Date.now() + parseFloat(penalty) * 1000;
st.busy.handshake.splice(st.busy.handshake.indexOf(t), 1);
st.todo.handshake.unshift(t);
return;
}
st.bytes.uploaded += t.size;
if (rsp.indexOf('partial upload exists') !== -1 ||
rsp.indexOf('file already exists') !== -1) {