Commit 42f85155 authored by Alain Takoudjou's avatar Alain Takoudjou

erp5_web_mynij_search: Prevent failing on all sitemap urls if there is a problem on network

parent 5de0c9e7
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
} }
function showError(error_message) { function showError(error_message) {
console.log(error_message); console.error(error_message);
} }
gadget_klass gadget_klass
...@@ -36,7 +36,8 @@ ...@@ -36,7 +36,8 @@
return this.getDeclaredGadget("model") return this.getDeclaredGadget("model")
.push(function (model) { .push(function (model) {
return gadget.changeState({ return gadget.changeState({
model_gadget: model model_gadget: model,
failurelimit: 10
}); });
}); });
}) })
...@@ -96,6 +97,7 @@ ...@@ -96,6 +97,7 @@
return RSVP.delay(5000); return RSVP.delay(5000);
else { else {
gadget.state.current_build = entry; gadget.state.current_build = entry;
gadget.state.failedcount = 0;
link_list = entry.links.split("\n").filter(l => l.length > 0); link_list = entry.links.split("\n").filter(l => l.length > 0);
return gadget.build_index(link_list, entry.index_name) return gadget.build_index(link_list, entry.index_name)
.push(function (build_failed) { .push(function (build_failed) {
...@@ -224,7 +226,7 @@ ...@@ -224,7 +226,7 @@
return gadget.get_and_handle(link, name); return gadget.get_and_handle(link, name);
}) })
.push(undefined, function (error) { .push(undefined, function (error) {
console.log(error); console.error(error);
failed = true; failed = true;
}); });
} }
...@@ -233,7 +235,8 @@ ...@@ -233,7 +235,8 @@
} }
return build_queue return build_queue
.push(function () { .push(function () {
return failed; return failed ||
gadget.state.failedcount >= gadget.state.failurelimit;
}); });
}) })
...@@ -356,6 +359,10 @@ ...@@ -356,6 +359,10 @@
.declareMethod("get_sitemap_item", function (link, index_name, attempt) { .declareMethod("get_sitemap_item", function (link, index_name, attempt) {
var gadget = this; var gadget = this;
if (gadget.state.failedcount >= gadget.state.failurelimit) {
// too much successive failure, prevent to loop
return;
}
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
var rng = Math.floor(Math.random() * Math.floor(gadget.state.proxies.length)), var rng = Math.floor(Math.random() * Math.floor(gadget.state.proxies.length)),
...@@ -363,21 +370,18 @@ ...@@ -363,21 +370,18 @@
return jIO.util.ajax({url : proxy + "?url=" + link}); return jIO.util.ajax({url : proxy + "?url=" + link});
}) })
.push(function (page) { .push(function (page) {
// reset failed counter
gadget.state.failedcount = 0;
if (page !== undefined) { if (page !== undefined) {
return gadget.parse_sitemap_item(page, index_name); return gadget.parse_sitemap_item(page, index_name);
} }
else else
return null; return null;
}) })
.push(undefined, function (my_error) { .push(undefined, function (error) {
if (!my_error.target) { gadget.state.failedcount += 1;
showError(my_error); showError("Failed to get url: " + link);
} else if (my_error.target.status === 500 && attempt <= 3) { showError(error);
return gadget.get_sitemap_item(link, index_name, attempt + 1);
console.log("Retry " + (attempt + 1) + " on url: " + link);
}
else
showError(my_error);
}); });
}) })
......
...@@ -242,7 +242,7 @@ ...@@ -242,7 +242,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>994.61246.30369.5734</string> </value> <value> <string>994.62669.7856.4232</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -260,7 +260,7 @@ ...@@ -260,7 +260,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1632233029.49</float> <float>1632319215.7</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment