minor #41115 [WebProfilerBundle] Add simple backoff strategy on 404 (loevgaard)
This PR was squashed before being merged into the 5.3-dev branch.
Discussion
----------
[WebProfilerBundle] Add simple backoff strategy on 404
| Q | A
| ------------- | ---
| Branch? | 5.x
| Bug fix? | no
| New feature? | yes
| Deprecations? | no
| Tickets | Fix https://github.com/symfony/symfony/issues/41112
| License | MIT
Instead of just retrying every second 5 times, this PR implements a very basic backoff strategy where it waits 1, 1, 2, 3, 5 seconds between the respective requests instead which amounts to a total wait of 12 seconds instead of 5.
Commits
-------
f1b9684ebd
[WebProfilerBundle] Add simple backoff strategy on 404
This commit is contained in:
commit
173cf480eb
@ -37,10 +37,12 @@
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
var request = function(url, onSuccess, onError, payload, options) {
|
var request = function(url, onSuccess, onError, payload, options, tries) {
|
||||||
var xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
|
var xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
|
||||||
options = options || {};
|
options = options || {};
|
||||||
options.maxTries = options.maxTries || 0;
|
options.maxTries = options.maxTries || 0;
|
||||||
|
tries = tries || 1;
|
||||||
|
var delay = Math.pow(2, tries - 1) * 1000;
|
||||||
xhr.open(options.method || 'GET', url, true);
|
xhr.open(options.method || 'GET', url, true);
|
||||||
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
|
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
|
||||||
xhr.onreadystatechange = function(state) {
|
xhr.onreadystatechange = function(state) {
|
||||||
@ -51,8 +53,8 @@
|
|||||||
if (xhr.status == 404 && options.maxTries > 1) {
|
if (xhr.status == 404 && options.maxTries > 1) {
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
options.maxTries--;
|
options.maxTries--;
|
||||||
request(url, onSuccess, onError, payload, options);
|
request(url, onSuccess, onError, payload, options, tries + 1);
|
||||||
}, 1000);
|
}, delay);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user