Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Slacklet for Monitoring Herald API
monitoring = true
main = ->
send '监控程序已上线'
loop
if not monitoring
send '监控程序已退出'
break
downCount = 0
res = await (axios.get 'https://www.heraldstudio.com/api/').catch (e) ->
res = data: e.message
unless (parseInt res?.statusCode) is 404
downCount += 1
test = (count) ->
return false if count == 1
while count % 10 == 0
count /= 10
return count in [1, 2, 5]
if test downCount
send "(发生#{ downCount }次) 到 Herald API 的定期请求不符合预期:" +
res?.statusCode + ' ' + JSON.stringify res?.data ? ''
else
if downCount > 1
send 'Herald API 的定期请求已恢复正常。'
downCount = 0
await sleep 10000
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.