cannawen / dota-gsi-discord-bot

Use Dota 2's Game State Integration API to make helpful announcements in a discord voice channel
MIT License
5 stars 2 forks source link

[feature] Handle shutdown gracefully #45

Closed cannawen closed 1 year ago

cannawen commented 1 year ago
cannawen commented 1 year ago

Couldn't get redis to work. Saving to a file instead :) Useful links - https://community.fly.io/t/new-feature-graceful-vm-shutdown-options/504 https://community.fly.io/t/some-issues-with-volumes-on-apps-v2/11994

cannawen commented 1 year ago

Holy shirtballs. Needed to change Docker file to run node ./build/index.js instead of npm run start so our node process gets the SIGINT/SIGTERM signals instead of npm. It's working now though.

https://github.com/npm/npm/issues/4603

cannawen commented 1 year ago

Restarting production app during a game did not re-establish voice connection OR save data.

Logs running app from commit 26c6704dde37cb5cd58bf85233bfe93d30fe55ea

2023-04-06T16:32:53.387 app[e2865644f6e686] yyz [info] 2023-04-06 16:32:53 info [APP] Shutdown signal received.
2023-04-06T16:32:53.388 app[e2865644f6e686] yyz [info] 2023-04-06 16:32:53 info [APP] Notify 20d594ff682d61c52ed003bad86a05aa708d454fafb0115a3248a8f5c5a7b833 of shutdown
2023-04-06T16:32:53.388 app[e2865644f6e686] yyz [info] 2023-04-06 16:32:53 info [APP] Saving data {"20d594ff682d61c52ed003bad86a05aa708d454fafb0115a3248a8f5c5a7b833":{"studentId":"20d594ff682d61c52ed003bad86a05aa708d454fafb0115a3248a8f5c5a7b833","buyback":"PRIVATE","glhf":"PRIVATE","gold_reminder":"PRIVATE","neutral_item":"PRIVATE","pause":"NONE","roshan":"PUBLIC","runes":"PRIVATE","registerDiscordGuild":"472892759725047814","registerDiscordGuildChannel":"1082789689611792474","allEventsTopic":[{"type":"bounty_rune_pickup","time":248},{"type":"bounty_rune_pickup","time":616},{"type":"bounty_rune_pickup","time":929},{"type":"bounty_rune_pickup","time":987},{"type":"tip","time":1169},{"type":"bounty_rune_pickup","time":1331},{"type":"bounty_rune_pickup","time":1639},{"type":"bounty_rune_pickup","time":1638},{"type":"tip","time":1642},{"type":"bounty_rune_pickup","time":1706},{"type":"bounty_rune_pickup","time":1712},{"type":"aegis_picked_up","time":1764},{"type":"roshan_killed","time":1764}],"lastRemindedGoldTopic":2052,"roshanMaybeTimeTopic":1997,"roshanAliveTimeTopic":2177}}
2023-04-06T16:32:53.389 app[e2865644f6e686] yyz [info] Sending signal SIGINT to main child process w/ PID 521
2023-04-06T16:32:53.389 app[e2865644f6e686] yyz [info] 2023-04-06 16:32:53 info [APP] Http server closed.
2023-04-06T16:32:53.852 proxy[e2865644f6e686] yyz [error] instance refused connection. is your app listening on 0.0.0.0:8080? make sure it is not only listening on 127.0.0.1 (hint: look at your startup logs, servers often print the address they are listening on)
Failed to proxy HTTP request (error: no known healthy instances found for route tcp/80. (hint: is your app shutdown? is there an ongoing deployment with a volume or using the 'immediate' strategy? if not, this could be a delayed state issue)). Retrying in 20 ms (attempt 1)
2023-04-06T16:32:58.173 proxy[e2865644f6e686] yyz [warn] Failed to proxy HTTP request (error: no known healthy instances found for route tcp/443. (hint: is your app shutdown? is there an ongoing deployment with a volume or using the 'immediate' strategy? if not, this could be a delayed state issue)). Retrying in 1000 ms (attempt 10)
2023-04-06T16:32:58.410 app[e2865644f6e686] yyz [info] Sending signal SIGTERM to main child process w/ PID 521
2023-04-06T16:32:58.411 app[e2865644f6e686] yyz [info] 2023-04-06 16:32:58 info [APP] Shutdown signal received.
Failed to proxy HTTP request (error: no known healthy instances found for route tcp/80. (hint: is your app shutdown? is there an ongoing deployment with a volume or using the 'immediate' strategy? if not, this could be a delayed state issue)). Retrying in 985 ms (attempt 10)
Failed to proxy HTTP request (error: no known healthy instances found for route tcp/80. (hint: is your app shutdown? is there an ongoing deployment with a volume or using the 'immediate' strategy? if not, this could be a delayed state issue)). Retrying in 23 ms (attempt 1)
2023-04-06T16:33:02.361 app[e2865644f6e686] yyz [warn] Virtual machine exited abruptly
2023-04-06T16:33:02.951 app[e2865644f6e686] yyz [info] Starting init (commit: 9e69c24)...
2023-04-06T16:33:02.964 app[e2865644f6e686] yyz [info] Mounting /dev/vdb at /data w/ uid: 0, gid: 0 and chmod 0755
2023-04-06T16:33:02.967 app[e2865644f6e686] yyz [info] Preparing to run: `node ./build/index.js` as root
2023-04-06T16:33:02.980 app[e2865644f6e686] yyz [info] 2023/04/06 16:33:02 listening on [fdaa:1:c218:a7b:f0:1117:50b7:2]:22 (DNS: [fdaa::3]:53)
2023-04-06T16:33:03.977 app[e2865644f6e686] yyz [info] 2023-04-06 16:33:03 info [APP] Starting server on http://0.0.0.0:8080
2023-04-06T16:33:04.548 app[e2865644f6e686] yyz [info] 2023-04-06 16:33:04 info [DISCORD] Discord ready with bot: dota-coach#9402
2023-04-06T16:33:04.549 app[e2865644f6e686] yyz [info] 2023-04-06 16:33:04 info [APP] Reading data
2023-04-06T16:33:04.700 proxy[e2865644f6e686] yyz [error] could not make HTTP request to instance: error from user's HttpBody stream: error reading a body from connection: end of file before message length reached
2023-04-06T16:33:04.706 app[e2865644f6e686] yyz [info] BadRequestError: request aborted
2023-04-06T16:33:04.706 app[e2865644f6e686] yyz [info] at IncomingMessage.onAborted (/app/node_modules/raw-body/index.js:238:10)
2023-04-06T16:33:04.706 app[e2865644f6e686] yyz [info] at IncomingMessage.emit (node:events:513:28)
2023-04-06T16:33:04.706 app[e2865644f6e686] yyz [info] at IncomingMessage._destroy (node:_http_incoming:224:10)
2023-04-06T16:33:04.706 app[e2865644f6e686] yyz [info] at _destroy (node:internal/streams/destroy:109:10)
2023-04-06T16:33:04.706 app[e2865644f6e686] yyz [info] at IncomingMessage.destroy (node:internal/streams/destroy:71:5)
2023-04-06T16:33:04.706 app[e2865644f6e686] yyz [info] at abortIncoming (node:_http_server:744:9)
2023-04-06T16:33:04.706 app[e2865644f6e686] yyz [info] at socketOnClose (node:_http_server:738:3)
2023-04-06T16:33:04.706 app[e2865644f6e686] yyz [info] at Socket.emit (node:events:525:35)
2023-04-06T16:33:04.706 app[e2865644f6e686] yyz [info] at TCP.<anonymous> (node:net:317:12)
2023-04-06T16:35:36.297 app[e2865644f6e686] yyz [info] 2023-04-06 16:35:36 info [DISCORD] Handling slash command interaction coachme
2023-04-06T16:35:36.305 app[e2865644f6e686] yyz [info] 2023-04-06 16:35:36 info [DISCORD] Discord ready with guild: hk's place channel: general
2023-04-06T16:35:36.517 app[e2865644f6e686] yyz [info] 2023-04-06 16:35:36 info [DISCORD] VoiceConnection ready to play audio for student 20d594ff682d61c52ed003bad86a05aa708d454fafb0115a3248a8f5c5a7b833!
cannawen commented 1 year ago

I think it's fine now... We are registering topics so we can find the correct topic to serialize the data with

cannawen commented 1 year ago

Topics could be registering themselves from the constructor, but that brings some questionable dependencies to Topic ... need to ponder this further

cannawen commented 1 year ago

Removed restart notification in 36a24399e529d9b88add80bddae731b8f4901400