Last active
June 28, 2018 12:38
-
-
Save tuor4eg/ebca5a3fa4a6be48fdd6bf535914f2e5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default (backendUrl, currentUrl) => { | |
return new Promise((resolve, reject) => { | |
get(backendUrl) | |
.then(response => { | |
if (response.status !== 200) { | |
reject(new Error(response.status)); | |
return; | |
} | |
const parseJs = JSON.parse(response.data); | |
Promise.all(parseJs.map(element => { | |
return get(`${element.url}/status`).then(response => JSON.parse(response.data)); | |
})) | |
.then(response => response.sort((a, b) => a.workload > b.workload)) | |
.then(response => post(currentUrl, {value: response[0].url})) | |
.then(response => { | |
if (response.status !== 201) { | |
reject(new Error(response.status)); | |
return; | |
} | |
resolve(response); | |
}); | |
}); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment