-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
218 additions
and
6 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const axios = require('axios') | ||
const CHECK_TIME = 5000 | ||
const TIMEOUT = 60000 | ||
|
||
const sleep = function (time) { | ||
return new Promise((resolve) => { | ||
setTimeout(resolve, time) | ||
}) | ||
} | ||
|
||
async function checkup(url) { | ||
return new Promise(async (resolve, reject) => { | ||
let up = false | ||
const startTime = new Date().getTime() | ||
while (!up) { | ||
if (new Date().getTime() - startTime > TIMEOUT) { | ||
up = true | ||
return reject('check up fail') | ||
} | ||
try { | ||
console.log('检查是否在线: ', url) | ||
await axios.get(url) | ||
console.log('已经在线') | ||
up = true | ||
} catch (e) { | ||
console.log(e.message) | ||
await sleep(CHECK_TIME) | ||
} | ||
} | ||
console.log('duration:', new Date().getTime() - startTime) | ||
resolve() | ||
}) | ||
} | ||
|
||
module.exports = { | ||
sleep, | ||
checkup | ||
} |
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
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
Oops, something went wrong.